these issues overwhelmed my mind commonly.
the differences among scanner, string tokenizer and split..
they are same but different.. i'll show you..
1. split
String test = "kuascoklat is cumakatasaya"; String[] tokens = test.split(" "); // Single blank is the separator. System.out.println(Arrays.toString(tokens));
2. scanner
String test = "kuascoklat is cumakatasaya"; ArrayListtokens = new ArrayList (); Scanner tokenize = new Scanner(test); while (tokenize.hasNext()) { tokens.add(tokenize.next()); } System.out.println(tokens);
3. string tokenizer
String[] stringToArray(String wordString) { String[] result; int i = 0; // index into the next empty array element //--- Declare and create a StringTokenizer StringTokenizer st = new StringTokenizer(wordString); //--- Create an array which will hold all the tokens. result = new String[st.countTokens()]; //--- Loop, getting each of the tokens while (st.hasMoreTokens()) { result[i++] = st.nextToken(); } return result; }
these algorithms will give us same result. but the third one will make some differences and it's the most inefficient one between other. i've tried the stringtokenizer and the split. and maybe i'll try another one. wanna try? :)
this is under MIT license. thanks. :)
0 their words:
Post a Comment
hello, any opinion? feel free to comment :)