Last active
February 23, 2017 04:08
-
-
Save dilipbobby/b9389175315078e4355bc0e121af7ab6 to your computer and use it in GitHub Desktop.
This code is a normal example for writing the split method and using it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MySplit { | |
public static String[] mySplit(String text, String delimiter) { | |
java.util.List<String> parts = new java.util.ArrayList<String>(); | |
text += delimiter; | |
for (int i = text.indexOf(delimiter), j=0; i != -1;) { | |
String temp = text.substring(j,i); | |
if(temp.trim().length() != 0) { | |
parts.add(temp); | |
} | |
j = i + delimiter.length(); | |
i = text.indexOf(delimiter,j); | |
} | |
return parts.toArray(new String[0]); | |
} | |
public static void main(String[] args) { | |
String str = "004-034556"; | |
String delimiter = "-"; | |
String result[] = mySplit(str, delimiter); | |
for(String s:result) | |
System.out.println(s); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment