public class StringMethods { public static void main(String[] args) { // TODO Auto-generated method stub String str = "John, Jennie, Jim, Jack, Joe"; int len = str.length(); System.out.println("Length of str is: " +len); System.out.println(str.charAt(0) + "|" + str.charAt(len-1)); String s1 = str.toUpperCase(); System.out.println("str after upper case is: " + str); //no changes, strings are immutable System.out.println("s1 is: "+s1); //new string will created, old string will not be changed. if (str.contains("Jim")) { System.out.println("Jim is in the string"); } String s2 = str.substring(5); System.out.println("s2 is: "+s2); String s3 = str.substring(6, 10); //start with 6th index till 9 index i.e. less than 10 System.out.println("s3 is: " +s3); String s4 = str.replace('J', 'K'); System.out.println("s4 is: " +s4); char[] chArr = str.toCharArray(); for(char ch:chArr) { System.out.println(ch + " "); } System.out.println(); String[] strArr = str.split(","); for (String s:strArr) { System.out.println(s.trim()); } //trim: String s = " Hello World "; System.out.println(s.trim()); System.out.println(s.replace(" ", "")); String date = "01-22-2019"; //01/22/2019 System.out.println(date.replace("-", "/")); //split: String test = "Hello_world_test_selenium"; String[] testval = test.split("_"); for(String strtest:testval) { System.out.println(strtest); } } }