CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Array Lookup?

  1. #1
    Join Date
    Mar 2000
    Posts
    123

    Array Lookup?

    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...


  2. #2
    Join Date
    May 2000
    Location
    NJ,USA
    Posts
    64

    Re: Array Lookup?

    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#


  3. #3
    Join Date
    Apr 1999
    Posts
    64

    Re: Array Lookup?

    Avoid the == when you mean .equal

    str.equal("txt1")


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured