String str = "Java~programming~is~cool";
String[] result = str.split("~");
String p1 = result[0];
String p2 = result[1];
String p3 = result[2];
String p4 = result[3];
System.out.println(p1);
System.out.println(p2);
System.out.println(p3);
System.out.println(p4);
The String.split() method in Java takes the separator string as a parameter and returns the array of elements. In the above code example, we have created a String variable str and we are splitting it using separator '~'.
0 Comments