Professional Documents
Culture Documents
length()
String String str = "Codecademy";
System.out.println(str.length());
// prints 10
concat()
String String String s1 = "Hello";
String String s2 = " World!";
String s3 = s1.concat(s2);
// concatenates strings s1 and s2
System.out.println(s3);
// prints "Hello World!"
equals()
true System.out.println(s1.equals("Hello"));
false
// prints true
System.out.println(s2.equals("Hello"));
.equalsIgnoreCase()
// prints false
System.out.println(s2.equalsIgnoreCase("wo
rld"));
// prints true
1 of 2 6/15/2021, 10:37 AM
https://www.codecademy.com/learn/learn-java/modules/learn-java-strin...
indexOf()
() System.out.println(str.indexOf("l"));
indexOf() // prints 2
System.out.println(str.indexOf("Wor"));
// prints 6
System.out.println(str.indexOf("z"));
// prints ‐1
charAt()
System.out.println(str.charAt(15));
// prints 'g'
String
String str = "Hello World!";
● toUpperCase()
String uppercase = str.toUpperCase();
// uppercase = "HELLO WORLD!"
● toLowerCase()
String lowercase = str.toLowerCase();
// lowercase = "hello world!"
2 of 2 6/15/2021, 10:37 AM