1String string = "004-034556";
2String[] parts = string.split("-");
3String part1 = parts[0]; // 004
4String part2 = parts[1]; // 034556
5
1String yourString = "Hello/Test/World";
2String[] strings = yourString.split("/" /*<- Regex */);
3
4Output:
5strings = [Hello, Test, World]
1public class SplitExample2 {
2 public static void main(String args[])
3 {
4 String str = "My name is Chaitanya";
5 //regular expression is a whitespace here
6 String[] arr = str.split(" ");
7
8 for (String s : arr)
9 System.out.println(s);
10 }
11}
1String textfile = "ReadMe.txt";
2String filename = textfile.split(".")[0];
3String extension = textfile.split(".")[1];
1String s = "abc{def";
2String[] arr = s.split("\\{");
3String s1 = arr[0]; // abc
4String s2 = arr[1]; // def