String string = "004-034556";
String[] parts = string.split("-");
String part1 = parts[0]; // 004
String part2 = parts[1]; // 034556
String yourString = "Hello/Test/World";
String[] strings = yourString.split("/" /*<- Regex */);
Output:
strings = [Hello, Test, World]
Java example to split a string
String str = "A-B-C-D";
String[] strArray = str.split("-");
System.out.println(Arrays.toString(strArray)); // [A, B, C, D]
String[] array = values.split("|", -1);
String str= "abcdef";
String[] array=str.split("(?<=G.{2})");
System.out.println(java.util.Arrays.toString(array));
public class MyClass {
public static void main(String args[]) {
String data = "1,2,3,,5,6,,";
String[] split = data.split(",", -1);
for (int i=0; i<split.length; i++)
System.out.println(split[i]);
System.out.println("Done");
}
}
List<String> list = new ArrayList<String>(Arrays.asList(scanner.nextLine().split(", ")));