Click to See Complete Forum and Search --> : Array Lookup?


daileyps
September 25th, 2000, 10:03 AM
How do you lookup array elements in Java?

Have String{} MyArray = { txt1, txt2, txt3 };

if I have myVar and want to check if it is in MyArray...

vasgaddam
September 25th, 2000, 01:12 PM
Hi, u can lookup array just like this..
If u have an String array like this, and u want to lookup "myVar" in that array,
String[] arr = {"txt1","txt2","myVar"};
for ( int i=0; i<arr.length; i++ )
{
if ( arr[i] == "myVar" )
{
System.out.println(arr[i]);
}
}

Sreeni
#If this post is valid to u, then dont forget to rate it#

Philip McGahan
September 26th, 2000, 12:26 PM
Avoid the == when you mean .equal

str.equal("txt1")