Saved Bookmarks
| 1. |
What is the best way to split a string in Java? |
|
Answer» Split() is a Java method for breaking a string based on a Java string delimiter (specified REGEX). For example, a space or a comma(,) will usually be used as the Java string split attribute to break or split the string. Syntax: string.split(String regex, INT limit)Here,
Example: public class SplitString { public static void main(String[] ARGS) { String str = "Scaler by InterviewBit"; // split string from space String[] result = str.split(" "); for (int i=0; i < result.length; i++) { System.out.println(result[i]); } }}Output: ScalerbyInterviewBit |
|