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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

indexOf

Status
Not open for further replies.

21091958

Programmer
Aug 21, 2005
20
GB
Hello all
I am newbie in java, I have an arrayList of elements (String), i need to be able to read the index of any element of that list
I have tried that but no good
public E indexOf (int index){
if (index<0 || index>=size)
throw new IndexOutOfBoundsException(""+index);

for(int i=0; i<size;i++ )
if (E[]theArray = theArray[index])
r = theArray[index];
return r;
}
cheers
 
String s = (String)arrayList.get(index);

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Hi Sedj
This code return this error
cannot invoke get(int) on the array type [E]
Thank you
 
do you have an array, or an ArrayList?

Note that you need two equal-signs for comparision:
if (a==b) - not if (a = b).
But for Objects, you will normally use 'equals'
if (a.equals (b))


seeking a job as java-programmer in Berlin:
 
Well you did say you had an arrayList - which I took to mean java.util.ArrayList !

Change this line :

if (E[]theArray = theArray[index])

to :

if (E[]theArray.equals(theArray[index]))

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top