String class. Using String. line = "Geek1 \nGeek2 \nGeek3". In this example, we are simply splitting the string using the space as a delimiter. This is optional. . OFF.
Java split string by space
Char array. To split by all white space characters (spaces, tabs etc) use the delimiter “\\s+“. split(String regex, int limit) Where, regex = Java splits the string based on this delimiter, limit = number of substrings returned. The Java String split() method divides the string at the specified separator and returns an array of substrings. . Scanner; public class TwoString { public static void main(String[] args) { Scanner sc = new Scanner(System. Each part is called a token.