About 50 results
Open links in new tab
  1. How do I compare strings in Java? - Stack Overflow

    Apr 2, 2013 · At the end of this Java String comparison tutorial I'll also discuss why the "==" operator doesn't work when comparing Java strings. Option 1: Java String comparison with the equals method …

  2. String Comparison in Java - Stack Overflow

    Oct 31, 2010 · 0 Below Algo "compare two strings lexicographically" Input two strings string 1 and string 2. for (int i = 0; i < str1.length () && i < str2.length (); i ++) (Loop through each character of both …

  3. java - String.equals versus == - Stack Overflow

    That's why == often doesn't work on Strings; Strings are objects, and doing == on two string variables just compares if the address is same in memory, as others have pointed out. .equals() calls the …

  4. Comparing some strings in Java - Stack Overflow

    Aug 5, 2023 · 7 If you want to compare Strings, then you should use String.equals() (or String.equalsIgnoreCase()) method. Comparing by == tells you only if two references points to same …

  5. Comparing two Strings using Java 8 features - Stack Overflow

    I was exploring various efficient ways to compare two strings in Java and I was comparing below two code snippets Approach 1 :- Traditional Way public static boolean stringCheck(String test1, S...

  6. java - compare two numeric String values - Stack Overflow

    String string1 = "4"; // and String string2 = "04"; Both the values are equal but how to compare them in java? We have equals and equalsIgnoreCase for comparing String alpha values, similarly how to …

  7. Compare two objects in Java with possible null values

    Since Java 7 you can use the static method java.util.Objects.equals(Object, Object) to perform equals checks on two objects without caring about them being null. If both objects are null, it will return true, …

  8. How to use the Comparable CompareTo on Strings in Java

    Sep 20, 2010 · Also in your code, do not try to compare Strings using '=='. Use 'equals' method instead. '==' only compare string references while equals semantically compares two strings.

  9. What is the difference between == and equals () in Java?

    In Java, the == operator compares the two objects to see if they point to the same memory location; while the .equals() method actually compares the two objects to see if they have the same object value.

  10. What's the quickest way to compare strings in Java?

    Sep 27, 2010 · Having said that: a.equals (b) is really fast for Strings. It's probably one of the most tightly optimized pieces of code in the Java platform. I'd be very surprised if you can find any faster way of …