Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-26-2008, 08:42 PM
Member
 
Join Date: May 2008
Posts: 3
lareauk is on a distinguished road
Can I store multiple objects in an array
I am working on an array and want to store entries that will have multiple objects - for example a student, a student with a car, etc.

I know the syntax to store one object, but not multiples.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-27-2008, 05:03 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
try ArrayList<Object>
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-27-2008, 05:07 AM
Member
 
Join Date: May 2008
Posts: 3
lareauk is on a distinguished road
Multiple object in an array
I am new this this forum, so wasn't quite sure what or how to ask.

I managed to solve this by storing objects within objects prior to storing within an array. For example, I put the car object (which contains brand, cost & miles) into the student object prior to putting into the array.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-27-2008, 06:33 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Can you show your code, what you have done up to now.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-27-2008, 12:07 PM
M77's Avatar
M77 M77 is offline
Member
 
Join Date: May 2008
Location: LV
Posts: 36
M77 is on a distinguished road
Send a message via Skype™ to M77
Object[] arr = new Object[10];
arr[0]="Ordinary String";
arr[1]=new Integer(77);
System.out.println((String)arr[0]);
if (arr[1] instanceof Integer) System.out.println(((Integer)arr[1]).toString());
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-28-2008, 04:57 AM
Member
 
Join Date: May 2008
Posts: 3
lareauk is on a distinguished road
Here is my solution
I pass information to this method which can include just the student info or the student info and either a credit card object or a car object, which then gets stored in the array.

//An array for holding students and their information
//about credit cards and cars.
protected Student[] studentCollection;

//for holding the total number of items in Student array
protected int manyItems = 0;

/**
* Method to create classroom based on size from tester
*/
public ClassRoom (int size)
{
StudentCollection = new Student[size];
}

/**
* Method to populate array with only Student information
*/
public void addStudent (Student newStudent, int index)
{
studentCollection[index] = newStudent;
manyItems++;
}

/**
* Method to populate array with Student & CreditCard information
*/
public void addStudent (Student newStudent, CreditCard newCreditCard,
int index)
{
studentCollection[index] = newStudent;
manyItems++;
}

/**
* Method to populate array with Student & Car information
*/
public void addStudent (Student newStudent, Car newCar, int index)
{
studentCollection[index] = newStudent;
manyItems++;
}
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-28-2008, 11:58 PM
Member
 
Join Date: May 2008
Posts: 21
gogoc is on a distinguished road
any array or any thing other then primitive types are objects in java so u can store any thing in an object array .
__________________
get new coding problems at
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-29-2008, 05:51 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Including strings too. It's not a primitive data type. Most of the people confused on it.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 05-29-2008, 05:55 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Zosden is on a distinguished road
you could store primitive too if you do new Integer(42)
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 05-29-2008, 05:57 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Yes thats true.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you read from a file, and then store the info in an array? szimme101 New To Java 5 07-30-2008 11:30 AM
Can I use vectors to store multiple types of objects Nathand Advanced Java 6 04-28-2008 09:55 AM
How would you get information from a file and then store it in an array? szimme101 Advanced Java 3 04-07-2008 08:02 PM
questions about using array to store profile hien_NU New To Java 6 01-08-2008 07:03 AM


All times are GMT +3. The time now is 11:33 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org