how to compare multiple string objects simultaneously

M

Madhur Ahuja

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
 
A

andrewh1

Madhur said:
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
 
A

Andrew Thompson

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top