programming-examples/java/_Basics/How to split a string into a number of substrings.java

23 lines
705 B
Java
Raw Normal View History

2019-11-15 12:59:38 +01:00
public class JavaStringSplitEmp {
public static void main(String args[]) {
String str = "jan-feb-march";
String[] temp;
String delimeter = "-";
temp = str.split(delimeter);
for (int i =0; i < temp.length ; i++) {
System.out.println(temp[i]);
System.out.println("");
str = "jan.feb.march";
delimeter = "\\.";
temp = str.split(delimeter);
}
for (int i =0; i < temp.length ; i++) {
System.out.println(temp[i]);
System.out.println("");
temp = str.split(delimeter,2);
for (int j =0; j < temp.length ; j++) {
System.out.println(temp[i]);
}
}
}
}