谁能告诉我这个程序里nextToken()到底是指的哪些值?
关于nextToken()的使用方法我不是很懂谁能教教我??
import java.util.*;
import java.lang.*;public class stringtokenizer {
public static void main(String args[]) {
String cgiS =
"name =Lily&age = 10&address = ? &search for = toy,book"; StringTokenizer st = new StringTokenizer(cgiS, "&");
try {
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
String con = st.nextToken(); if (!con.equals("?")) {
System.out.println(":" + con);
} else {
System.out.println(":unknown");
}
} } catch (NoSuchElementException e) { } }
}
关于nextToken()的使用方法我不是很懂谁能教教我??
import java.util.*;
import java.lang.*;public class stringtokenizer {
public static void main(String args[]) {
String cgiS =
"name =Lily&age = 10&address = ? &search for = toy,book"; StringTokenizer st = new StringTokenizer(cgiS, "&");
try {
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
String con = st.nextToken(); if (!con.equals("?")) {
System.out.println(":" + con);
} else {
System.out.println(":unknown");
}
} } catch (NoSuchElementException e) { } }
}
String con = st.nextToken();
这样你连续两次取
你应该先String con = st.nextToken();
然后System.out.println(con)
list.add("b");
list.add("c");
list.add("d"); for (Iterator it = list.iterator(); it.hasNext();){
if(it.next().toString()=="d"){
System.out.println("true");
//break;
}else{
System.out.println("false");
}
}
if(it.next().equals("d")){
System.out.println("true");
//break;
}else{
System.out.println("false");
}