我目前正在使用 StringTokennizer 类将字符串拆分为不同的标记,如定义的分隔符..
public class App {
public static void main(String[] args) {
String str = "This is String , split by StringTokenizer, created by Neera";
StringTokenizer st = new StringTokenizer(str);
System.out.println("---- Split by comma ',' ------");
StringTokenizer st2 = new StringTokenizer(str, ",");
while (st2.hasMoreElements()) {
System.out.println(st2.nextElement());
}
}
}
我的疑问是,同样的事情也可以通过扫描仪类来实现......!!自从我阅读以来,使用扫描仪类是否正确? t工作...请告诉我..!!!
public class App1 {
public static void main(String[] args)
{
Scanner scanner = new Scanner("This is String , split by StringTokenizer, created by Neera").useDelimiter(", ");
while (scanner.hasNextLine()) {
System.out.println(scanner.nextLine());
}
}
}