Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java split first occurrence

// string.split(String pattern, int limit);
// limit: controls the number of times pattern is applied

String str = "boo:and:foo";		
// The next statement splits on first occurrence of ":"
System.out.println(Arrays.toString(str.split(":", 2))); // [boo, and:foo]
// The next statement splits on both occurrences of ":"
System.out.println(Arrays.toString(str.split(":", 3))); // [boo, and, foo]
 
PREVIOUS NEXT
Tagged: #java #split #occurrence
ADD COMMENT
Topic
Name
6+1 =