StringTokenizer using substring and indexOf
This String Tokenizer using SubString and indexof method checks character based on the position of the
delimiter,but in String tokenizer method in Java checks for each character.
To parse the string using the delimiter.This function parse the string and returns the parsed strings as a ArrayList.
This String Tokenizer using SubString and indexof method checks character based on the position of the
delimiter,but in String tokenizer method in Java checks for each character.
To parse the string using the delimiter.This function parse the string and returns the parsed strings as a ArrayList.
// Input for example, String s= test1|test2|test3 and String delimiter "|" ie ArrayList resultList = tokenizer(s,delimiter); // to call the method public ArrayList tokenizer(String s, String delimiter) { String sub = null; int i = 0; int j = s.indexOf(delimiter); // First substring ArrayList ar = new ArrayList(); while( j >= 0) { sub = s.substring(i,j); ar.add(sub); i = j + 1; j = s.indexOf(delimiter, i); // Rest of substrings } sub = s.substring(i); // Last substring ar.add(sub); return ar; }