How to Split String in Java with Example
Here you will learn how to split string in java. We can split string in Java using split() method of java.lang.String class. It takes a regular expression as an argument and returns an array of strings. Syntax:
1 |
public String[] split(String regex) |
Split String in Java Example Below program will split the string by space.
1 2 3 4 5 6 7 8 9 10 |
public class SplitStringJava { public static void main(String...s){ String str = "I Love Java Programming"; String strArray[] = str.split("\\s"); //split by space for(int i=0;i<strArray.length;++i){ System.out.println(strArray[i]); } } } |
Output …