应使用:
System.out.println((String)(e.next()));

解决方案 »

  1.   

    java.lang.ClassCastException这个错是指类型不匹配,也就是说e.next()返回值的类型
    System.out.println不认识.
      

  2.   

    但如果是System.out.println(e.next());系统并没有报错,而是我加了(String)e.next()时,才报错,这是不是说我根本就不能在这进行cast 类型转变呢?
      

  3.   

    这要看你在Iterator里面放的是什么类型的数据了,如果是String则用String来做cast,如果是别的类型的数据,则要用相应的类型来做cast。
    比如说Iterator里面放的是Integer类型则要:
    System.out.println((Integer)e.next());
    之所以System.out.println(e.next());这样也对,是因为java自动做了cast并调用相应类里面的toString()方法。
      

  4.   

    cast类型不匹配,
      可以使用上抛解决
      

  5.   

    不明白你为什么非要这么cast一下,如果你非要让它看起来像个String, 可以System.out.println(e.next().toString());
      

  6.   

    System.out.println的方法你看一下源代码就知道了,重载了很多,包括Object类型参数的。