Learn Java - String Methods Cheatsheet - Codecademy
Learn Java - String Methods Cheatsheet - Codecademy
String Methods
System.out.println(str.length());
// prints 10
String s3 = s1.concat(s2);
// concatenates strings s1 and s2
System.out.println(s3);
// prints "Hello World!"
System.out.println(s2.equalsIgnoreCase("world"));
// prints true
System.out.println(str.indexOf("Wor"));
// prints 6
System.out.println(str.indexOf("z"));
// prints -1
System.out.println(str.charAt(15));
// prints 'g'
toUpperCase() and toLowerCase() String Methods
In Java, we can easily convert a String to upper and lower case with the help of a few String str = "Hello World!";
string methods:
toUpperCase() returns the string value converted to uppercase.
toLowerCase() returns the string value converted to lowercase. String uppercase = str.toUpperCase();
// uppercase = "HELLO WORLD!"