50 likes | 65 Views
Strings. Modified 02/17/2016 by Laurie Murphy. Strings. name. String name;. ?. name = “ Jenn Lawrence ” ;. “ Jennifer Lawrence ”. “ Jenn Lawrence ”. name = “ Jennifer Lawrence ” ;. “ Jennifer Lawrence ”. Strings are immutable. String methods. String name = “ Katniss ” ;. name.
E N D
Strings Modified 02/17/2016 by Laurie Murphy
Strings name String name; ? name = “Jenn Lawrence”; “Jennifer Lawrence” “Jenn Lawrence” name = “Jennifer Lawrence”; “Jennifer Lawrence” Strings are immutable
String methods String name = “Katniss”; name System.out.println(name.toUpperCase()); System.out.println(name.toLowerCase()); “Katniss” System.out.println(“length = “ + name.length()); 0123456 System.out.println(“first = “ + name.charAt(0)); System.out.println(“last = “ + name.charAt(6)); System.out.println(“last = “ + name.charAt(7)); KATNISS katniss length = 7 first = K last = s Exception in thread “main” java.lang.StringIndexOutOfBoundsException
String Practice – What’s the output? String greeting = “Hello World!”; System.out.println(greeting.toUpperCase()); System.out.println(greeting.length()); System.out.println(greeting.charAt(9)); System.out.println(greeting.charAt(greeting.length());
Pair Practice Download and complete StringPractice.java