String Class

Split String in Java

Splits a string into parts based on a regex (usually a space) and stores it into an String array.

String[] splitString = bigString.split(regex);


The regex is a string used to determine where to split the bigger string. For example, to extract individual words from a sentence, a space would be used as a regex.

An optional integer can be passed as a second parameter to limit the number of strings returned.

String pets = "dog,cat";
String[] petsArray = pets.split(","); //will split names using comma as delimiter
System.out.println(petsArray[0]); //will output "dog"

Add to Slack

< String Trim   |   Substring >

© 2019 SyntaxDB. All Rights Reserved.