3

Im working with String Tokenizer API. Im not using Split() because Im working with jdk 1.3.

I have an input String which is given below

String input="Open_filedesc_count:mix:-1:-1:longterm:HML Max_filedesc_count:mix:-1:-1:longterm:HML,Percent_usage:mix:-1:95/90/85:standard:HML, Availability:mix:1/-/-:-1";

Now i would like to tokenize the string , The output should be like

Open_filedesc_count
Percent_usage
Availability

It simply eliminates most of the strings. but i want the output as mentioned above.

I tried three type of constructors but couldnt get the output as mentioned format

2 Answers 2

3
StringTokenizer tokenizer = new StringTokenizer(input, ",");
while (tokenizer.hasMoreElements()) {
    StringTokenizer tokenizer2 = new StringTokenizer(tokenizer.nextToken(), ":");
    System.out.println(tokenizer2.nextToken());
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a Lot :) correct answer !!! :D :) Explain all , it would be helpful to all of us !!!
2

Try,

String input = "Open_filedesc_count:mix:-1:-1:longterm:HML
                Max_filedesc_count:mix:-1:-1:longterm:HML,
                Percent_usage:mix:-1:95/90/85:standard:HML,
                 Availability:mix:1/-/-:-1";

  StringTokenizer tokenizer = new StringTokenizer(input, ",");

  while(tokenizer.hasMoreTokens()){          
    String token=tokenizer.nextToken();
    System.out.println(token.substring(0, token.indexOf(':')));
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.