String Length

String s = "This";
System.out.println(s.length());

String t = "This \"is\" that"; System.out.println(t.length());

String Length

String s = "This";
System.out.println(s.length());

String t = "This \"is\" that"; System.out.println(t.length());

String Length

String s = "This";
System.out.println(s.length());  // 4

String t = "This \"is\" that"; System.out.println(t.length());

String Length

String s = "This";
System.out.println(s.length());  // 4

String t = "This \"is\" that"; System.out.println(t.length());

String Length

String s = "This";
System.out.println(s.length());  // 4

String t = "This \"is\" that"; System.out.println(t.length()); // 14

String Comparison

String s1 = "This";
String s2 = "This";
String s3 = "this";

System.out.println(s1 == s2); System.out.println(s1 == s3);

String Comparison

String s1 = "This";
String s2 = "This";
String s3 = "this";

System.out.println(s1 == s2); // false System.out.println(s1 == s3); // false

String Comparison

String s1 = "This";
String s2 = "This";
String s3 = "this";

System.out.println(s1 == s2); // false System.out.println(s1 == s3); // false
System.out.println(s1.equals(s2)); System.out.println(s1.equals(s3));

String Comparison

String s1 = "This";
String s2 = "This";
String s3 = "this";

System.out.println(s1 == s2); // false System.out.println(s1 == s3); // false
System.out.println(s1.equals(s2)); // true System.out.println(s1.equals(s3)); // false

String Comparison

String s1 = "This";
String s2 = "That";

if(s1 < s2){ System.out.println("s1 comes first"); }else{ System.out.println("s2 comes first"); }

String Comparison

String s1 = "This";
String s2 = "That";

if(s1 < s2){ System.out.println("s1 comes first"); }else{ System.out.println("s2 comes first"); }

String Comparison

String s1 = "This";
String s2 = "That";

if(s1 < s2){ System.out.println("s1 comes first"); }else{ System.out.println("s2 comes first"); }

String Comparison

String s1 = "This";
String s2 = "That";

if(s1.compareTo(s2) < 0){ System.out.println("s1 comes first"); }else{ System.out.println("s2 comes first"); }

String Concatenation

String s1 = "This";
String s2 = "That";
int x = 42;

String s3 = s1 + s2; String s4 = "" + x;
System.out.println(s3); System.out.println(s4);

String Concatenation

String s1 = "This";
String s2 = "That";
int x = 42;

String s3 = s1 + s2; String s4 = "" + x;
System.out.println(s3); System.out.println(s4);

String Concatenation

String s1 = "This";
String s2 = "That";
int x = 42;

String s3 = s1 + s2; String s4 = "" + x;
System.out.println(s3); // "ThisThat" System.out.println(s4);

String Concatenation

String s1 = "This";
String s2 = "That";
int x = 42;

String s3 = s1 + s2; String s4 = "" + x;
System.out.println(s3); // "ThisThat" System.out.println(s4); // "42"

Searching Strings

  • contains
  • indexOf
  • lastIndexOf
  • startsWith
  • endsWith

Manipulating Strings

  • replace
  • substring
  • toLowerCase
  • toUppercase
  • trim
  • charAt