Check out example codes for "java split string". It will help you in understanding the concepts better.

Code Example 1

String string = "004-034556";
String[] parts = string.split("-");
String part1 = parts[0]; // 004
String part2 = parts[1]; // 034556

Code Example 2

public class SplitExample2 { 
    public static void main(String args[]) 
    { 
        String str = "My name is Chaitanya";
        //regular expression is a whitespace here 
        String[] arr = str.split(" "); 
  
        for (String s : arr) 
            System.out.println(s); 
    } 
}

Code Example 3

// Java program to demonstrate working of split(regex, 
// limit) with small limit. 
public class GFG { 
    public static void main(String args[]) 
    { 
        String str = "[email protected]@geekss"; 
        String[] arrOfStr = str.split("@", 2); 
  
        for (String a : arrOfStr) 
            System.out.println(a); 
    } 
}

Code Example 4

String yourString = "Hello/Test/World";
String[] strings = yourString.split("/" /*<- Regex */); 

Output:
strings = [Hello, Test, World]

Code Example 5

string phrase = "The quick brown    fox     jumps over the lazy dog.";
string[] words = phrase.Split(' ');

foreach (var word in words)
{
    System.Console.WriteLine($"<{word}>");
}

Learn ReactJs, React Native from akashmittal.com