Skip to content

Instantly share code, notes, and snippets.

@dilipbobby
Last active February 23, 2017 04:08
Show Gist options
  • Save dilipbobby/b9389175315078e4355bc0e121af7ab6 to your computer and use it in GitHub Desktop.
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
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