You are on page 1of 2

https://www.codecademy.com/learn/learn-java/modules/learn-java-strin...

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()

String String s1 = "Hello";


equals() String String s2 = "World";

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()

String String str = "Hello World!";

() 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()

String String str = "This is a string";


()
length()‐1 System.out.println(str.charAt(0));
// prints 'T'

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

You might also like