for(int i=0;i<input.length;i++) {
st5 = new StringTokenizer(input[i],",");
int tokCount = st5.countTokens();
int tkcount = 0;
while(st5.hasMoreElements()) {
tkcount++;
st5.nextToken();
if((tokCount - 2) == tkcount){
String str = st5.nextToken();
if(str.indexOf("-mCont") == -1)
break;
String mcount = str.substring(str.indexOf("-mCont")+1);
mcount = mcount.replace("mCont "," ");
System.out.println(mcount);
}
}
}
Taking Last Element of the Tokenized String using StringTokenizer API
-
01-09-2022 - |
Question
Im having a String Array as
String[] input = {"$abs gf ,sd df,$ascd sr adf dfa -mcont 100, 434" , "$abs,sd,$ascd sr adf dfa -mcont 900, 43" };
Now I tried to tokenize and got four Tokens.The thrid token last value say 100 and 900 on the above example which is my required output. From the four tokens, how can i go through only to the 3rd token last element???
Kindly use StringTokenizer API,I dont want String split() functions to handle it.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow