String length, charAt, equals : String Compare « Data Type « Java Tutorial






class StringDemo2 {
  public static void main(String args[]) {
    String strOb1 = "First String";
    String strOb2 = "Second String";
    String strOb3 = strOb1;
   
    System.out.println("Length of strOb1: " +
                       strOb1.length());
   
    System.out.println("Char at index 3 in strOb1: " +
                       strOb1.charAt(3));
   
    if(strOb1.equals(strOb2))
      System.out.println("strOb1 == strOb2");
    else
      System.out.println("strOb1 != strOb2");
   
    if(strOb1.equals(strOb3))
      System.out.println("strOb1 == strOb3");
    else
      System.out.println("strOb1 != strOb3");
  }
}








2.23.String Compare
2.23.1.Comparing Strings for Equality
2.23.2.To check for equality between two strings ignoring the case
2.23.3.Sequencing Strings
2.23.4.String length, charAt, equals
2.23.5.equals() and equalsIgnoreCase().
2.23.6.equals() vs ==
2.23.7.Region Matches
2.23.8.Compares all Strings in an array and returns the index at which the Strings begin to differ.
2.23.9.Compares all Strings in an array and returns the initial sequence of characters that is common to all of them.
2.23.10.Compares two Strings, and returns the index at which the Strings begin to differ.
2.23.11.Compares two Strings, and returns the portion where they differ.
2.23.12.Compress 2 adjacent (single or double) quotes into a single (s or d) quote when found in the middle of a String.