Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to compare strings in Java

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 195
    Comment on it

    There are two ways of comparison in Java. In you just want to match value of the string

    Object.equals() 
    

    will be used. It simply compares the string values. While if you use == to compare, it will check the object reference. So

    new String("test").equals("test") // --> true 
    new String("test") == "test" // --> false , since they are not the same object
    new String("test") == new String("test") // --> false, both point to different objects.
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: