谁能告诉我这个程序里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) {        }    }
    
}

解决方案 »

  1.   

    System.out.println(st.nextToken());
                    String con = st.nextToken();
    这样你连续两次取
    你应该先String con = st.nextToken();
    然后System.out.println(con)
      

  2.   

    建议你也看一下集合类(java.util.*)中的关于Iterator的使用
      

  3.   

    list.add("a");
        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");
         }
       }
      

  4.   


        if(it.next().equals("d")){
           System.out.println("true");
           //break;
         }else{
           System.out.println("false");
         }