-1
data_structures/ExpressionEvaluator.java:14: incompatible types.lang.String)
found   : java.util.StringTokenizer class data_structures.ExpressionEvaluator
required: java.util.Iterator<java.lang.String>ing> st = StringTokenize
        Iterator<String> st = new StringTokenizer(s);

Do I have to declare Iterator somewhere?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

2 Answers2

0

Look closer:

Iterator<String> st = new StringTokenizer(s);

You are declaring a variable st of type Iterator and on it you are creating a new object of type StringTokenizer. On the official specification:

http://docs.oracle.com/javase/1.4.2/docs/api/java/util/StringTokenizer.html

You can see an example of iterating a tokenized string.

Hernan Velasquez
  • 2,770
  • 14
  • 21
0

StringTokenizer class is used for string splitting and it is not being used much in these days. You can use split method in String class. Now coming to your problem, there is no Iterator associated with StringTokenizer and it make use of Enumeration.It looks like you are expecting an Iterator object out of StringTokenizerobject which does not even compile. So either code it enumeration and use String.split method to split it as array. Your code should be like

StringTokenizer tokenizer = new StringTokenizer(inputString);

while(tokenizer.hasMoreElements()) {
   String o = (String)tokenizer.nextElement();
   ......
   .......
}

or alternatively

String[]  splitted = inputString.split(delimter);
sakthisundar
  • 3,278
  • 3
  • 16
  • 29