File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Adding Object into an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Adding Object into an array" Watch "Adding Object into an array" New topic

Adding Object into an array

Kassi Hill

Joined: Sep 29, 2003
Posts: 24
I have a collection class that creates an array of objects in the constructor. I have a class that contains set and get methods to get the information out of the array created. I have another method that searches through the array for matches to what the user types in. If a match is found, then a boolean value is set to true and the matching inforation is printed out. What I need to do is put the matches found into another array and then loop through the foundMatches array. Below is the code that sets the boolean value, I cannot figure out how to then put the matches into another array.
for(int i=0;i<hotels.getSize();i++){
//verify hotels one at a time
Hotel oneHotel=hotels.getHotel(i);

//if at least one hotel is found
//print the information here.
This does work and I am able to get the information however, I need to be able to put it into a foundMatch arry to loop throuh to print out. Thank you for your help.
C. Nimo
Ranch Hand

Joined: Mar 23, 2004
Posts: 82

Shouldn't that suffice?
Kassi Hill

Joined: Sep 29, 2003
Posts: 24
I added the foundMatch(oneHotel); and that line compiled. Now when I try to loop through this array using:
for(int j=0; j<foundMatch.length; j++){
I cannot get the loop to compile, can you see a problem with it??
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
What error message is created by the compiler?
Often, it's very useful in pinpointing compiler errors.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Note that if I wanted to display a line of text to the system console, I'd likely use the command
System.out.println("some string");
Also, note the spelling of the println method.
nikos sokaf
Ranch Hand

Joined: May 01, 2004
Posts: 57
Look at the java.util.*; package.
Import java.util.*;

and then :
ArrayList a=new ArrayList();
a.add("Some String") or a.add(index,"Some String");
If you wanna handle the values:
Object o[]=a.toArray();
for(int i=0;i<o.length;i++)
or find another way to handle the values...It is easy
I agree. Here's the link:
subject: Adding Object into an array
It's not a secret anymore!