I have a Java String such as "10 20 30 40 50". I want to process these values using StringTokenizer basing on some business requirements multiple times.
For example, for certain condition, I want to double each of the values i.e., "20 40 60 80 100" and for another condition, I want to treble i.e., "30 60 90 120 150".
I found it can be done by creating multiple StringTokenizer, one for each condition. My question is, can it be done using a single instance of StringTokenizer? Please give efficient solution if any.
Here is my coding effort:
String str = "10 20 30 40 50";
StringTokenizer st = new StringTokenizer(str);
while(st.hasMoreTokens()){
int i = Integer.parseInt(st.nextToken())*2;
System.out.println(i);
}
Can I use the same instance 'st' for trebling the values?
EDIT : I know it can be done through another array or another list. But I want to know how I can reuse the same StringTokenizer for trebling as I did for doubling the values.