Skip to content

String Manipulation

Keyhan Hadjari edited this page Sep 13, 2016 · 4 revisions

String class

String class is imutable.

String Concatenation

System.out.println("A" + " B"); // "A B"
System.out.println(2 + "A" + "B"); // "2AB"
System.out.println(2 + 5 + "AB"); // "7AB"
String a = "A";
a += "B"; // "AB"
a += 33; // "AB33"
a += true; // "AB33true"

length

The length field returns length of the string.

charAt(int index)

Returns the character at the given index.

StringBuilder

StringBuilder class is mutable and not threadsafe

Clone this wiki locally