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];
1 class Test {
2 public static void main( String[] args) {
3 String[] result = "Stack Me 123 Heppa1 oeu".split("\\a");
4
5 // output should be
6 // S
7 // t
8 // a
9 // c
10 // k
11 // M
12 // e
13 // H
14 // e
15 // ...
16 for ( int x=0; x<result.length; x++) {
17 System.out.println(result[x] + "\n");
18 }
19 }
20 }
21