public class StringTest {
public static void main(String... args) {
String str = " some random String to-try in java . ";
String replacedString = str.replace(" ","");
System.out.printf("Str : '%s'\n", str);
System.out.printf("toLowerCase: '%s'\n", str.toLowerCase());
System.out.printf("toUpperCase: '%s'\n", str.toUpperCase());
System.out.printf("trim : '%s'\n", str.trim());
System.out.printf("length : '%s'\n", str.length());
System.out.printf("bytes : '%s'\n", Arrays.toString(str.getBytes()));
System.out.printf("replace : '%s'\n", str.replace(" ",""));
System.out.printf("startswith : '%s'\n", replacedString.startsWith("some"));
System.out.printf("endswith : '%s'\n", replacedString.endsWith("some"));
System.out.printf("split : " + Arrays.toString(str.split("-")) + "\n");
System.out.printf("charAt : '%s'\n", str.charAt(2));
System.out.printf("contains : '%s'\n", str.contains("random"));
System.out.printf("indexOf s : '%s'\n", str.indexOf('s'));
System.out.printf("lastIndexOf: '%s'\n", str.lastIndexOf('s'));
System.out.printf("toCharArray: "+Arrays.toString(str.toCharArray())+"\n");
System.out.printf("blank : '%s'\n", str.isBlank());
System.out.printf("empty : '%s'\n", str.isEmpty());
System.out.printf("equals : '%s'\n", str.equals("random"));
System.out.printf("intern : '%s'\n", str.intern());
$ java com/example/StringTest.java
Str : ' some random String to-try in java . '
toLowerCase: ' some random string to-try in java . '
toUpperCase: ' SOME RANDOM STRING TO-TRY IN JAVA . '
trim : 'some random String to-try in java .'
bytes : '[32, 32, 115, 111, 109, 101, 32, 114, 97, 110, 100, 111, 109, 32, 83, 116, 114, 105, 110, 103, 32, 116, 111, 45, 116, 114, 121, 32, 105, 110, 32, 106, 97, 118, 97, 32, 32, 46, 32]'
replace : 'somerandomStringto-tryinjava.'
split : [ some random String to, try in java . ]
toCharArray: [ , , s, o, m, e, , r, a, n, d, o, m, , S, t, r, i, n, g, , t, o, -, t, r, y, , i, n, , j, a, v, a, , , ., ]
intern : ' some random String to-try in java . '