Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about arrays

Status
Not open for further replies.

jisoo22

Programmer
Apr 30, 2001
277
0
0
US
Hello everyone!

I have a question about arrays. I was generally under the assumptiong that you could call a method from an object that's stored in an array directly, for instance as follows:

stuff s[];
s = new stuff[3];
//Assuming the 's' class object has a get method
s[1].get();

I have something similar in my program but I keep getting an error message that says it can't resolve the symbol 's' from the last line. This creates a problem as I'm using a for loop to run through my array so that I can get to each object's method and output a string result. Can anyone tell me if I'm doing this right or wrong?

Thanks,
Jisoo22
 
I'm not sure what you are doing wrong - I'm guessing a simple syntax error. The below seems to work, maybe it'll help ...

Code:
String a = "abc";
String b[] = new String[2];
b[0] = "ced";
b[1] = "abc";
System.out.println(b[0].equals(a));
System.out.println(b[1].equals(a));

(P.S. This is the Java(J2EE) forum - the forum for J2SE is here :: forum269 )
 
jisoo22,

do you initialize your array (like sedj does) with objects of type "stuff" ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top