hey,
Iv been looking around for an easy way to check if a string matches exactly and not just in a few characters I.E

B != "ABC"
B == B
Frederick != F

So only if the entire string matches will my condition be met. currently im using :

               String[] splitstring = linetoscan.split("[ ]+");
               //split entire input by spaces

              for(int j=0;j<splitstring.length;j++)
              {
                if(splitstring[j].contains("F"))
                {
                System.out.println("match found");
                }
              }

I read that the pattern matcher can be used, but seems a lot of conversion has to be done to compare a string to a pattern of characters? is pattern matcher the most light weight way to achieve this goal?

Do you mean string1.equals(string2) ?
(returns true only if both strings contain exactly the same sequence of characters)

commented: Answer is to the point of the question +11

or, for the String class, you also have the equalsIgnoreCase method, which will return true for both:

String a = "aBc";
a.equalsIgnoreCase("aBc");
a.equalsIgnoreCase("abc");

when you want to compare values of Objects, as JamesCherrill pointed out, you'll need the equals method. Only if you want to compare values of primitive types, you should use '==' or '!='.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.