how to compare multiple string objects simultaneously

Discussion in 'Java' started by Madhur Ahuja, Aug 4, 2004.

  1. Madhur Ahuja

    Madhur Ahuja Guest

    Hello
    If and nw and x[] are string object and array of strings.
    How do you compare all of them for equality.
    I tried it using:

    if(nw.equals(x[4].getLabel().equals(x[7].getLabel())))

    but produced the error:

    cannot resolve symbol method equals(boolean)

    Madhur Ahuja
    India
    Madhur Ahuja, Aug 4, 2004
    #1
    1. Advertising

  2. Madhur Ahuja

    andrewh1 Guest

    Madhur Ahuja wrote:

    > Hello
    > If and nw and x[] are string object and array of strings.
    > How do you compare all of them for equality.


    One at a time. If the array is not large then use equals(), otherwise
    you could call intern() and use == which will be much faster for very
    large arrays.

    read the docs for the String class.

    Cheers

    Andrew


    > I tried it using:
    >
    > if(nw.equals(x[4].getLabel().equals(x[7].getLabel())))
    >
    > but produced the error:
    >
    > cannot resolve symbol method equals(boolean)
    >
    > Madhur Ahuja
    > India
    >
    >
    >
    >
    andrewh1, Aug 4, 2004
    #2
    1. Advertising

  3. On Wed, 4 Aug 2004 14:58:37 +0530, Madhur Ahuja wrote:

    > If and nw and x[] are string object and array of strings.
    > How do you compare all of them for equality.


    Use a loop.

    > I tried it using:
    >
    > if(nw.equals(x[4].getLabel().equals(x[7].getLabel())))


    It would also help you very much to read the docs.
    <http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#equals(java.lang.Object)>

    > but produced the error:
    >
    > cannot resolve symbol method equals(boolean)


    ...and learn how to read and interpret errors
    <http://www.physci.org/codes/javafaq.jsp#exact>

    A better group for the moment might be..
    <http://www.physci.org/codes/javafaq.jsp#cljh>

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
    Andrew Thompson, Aug 4, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jimmy
    Replies:
    1
    Views:
    458
    bruce barker
    Jul 8, 2003
  2. Chad McCune
    Replies:
    2
    Views:
    618
    Chad McCune
    Jan 20, 2004
  3. Sebastian Millies
    Replies:
    0
    Views:
    367
    Sebastian Millies
    Mar 9, 2005
  4. Replies:
    3
    Views:
    388
    Tom Hawtin
    May 3, 2007
  5. dot c.
    Replies:
    1
    Views:
    100
    elise huard
    Apr 29, 2011
Loading...

Share This Page