This code isn't working!... | Core Java Forum
S
Shinia Posted on 06/12/2021

package com.programming.java;
import java.util.StringTokenizer;
public class StringTokenizerAPIExample {
public static void main(String[] args) {
StringTokenizerAPIExample st=new StringTokenizerAPIExample("Any random data from UI "," ");
while(st.hasMoreTokens())
{
System.out.println(st.nextToken());
}

}
}

//I got the error that the functions hasMoreTokens() and nextToken() are undefined for the type StringTokenizerAPIExample 


Y
Yogesh Chawla Replied on 06/12/2021

Functions hasMoreTokens() and nextToken() belong to StringTokenizer API of java.util package. Run this.

import java.util.StringTokenizer;

public class StringTokenizerAPIExample {
	public static void main(String[] args) {
		
		StringTokenizer st = new StringTokenizer(
				"Any random data from UI ", " ");
		while (st.hasMoreTokens()) {
			System.out.println(st.nextToken());
		}

	}
}


S
Shinia Replied on 12/12/2021

Ok...got it..thank you!


S
Shinia Replied on 12/12/2021

Sorry...But I already imported it?