- import java.util.Iterator;
- import java.util.LinkedList;
- public class Testw {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- LinkedList<String> lt =new LinkedList<String>();
- show(lt);
- show2(lt);
- }
- public static void show(LinkedList<String> lt ){
-
- lt.addFirst("feehg");
- lt.addFirst("fhrjwhg");
- lt.addFirst("fhjrjrrewhg");
- lt.addFirst("fhtjhg");
- Iterator<String> it=lt.iterator();
- while (it.hasNext()) {
- System.out.println(it.next());
-
- }
- }
- public static void show2(LinkedList<String> lt ){
-
- lt.addLast("feehg");
- lt.addLast("fhrjwhg");
- lt.addLast("fhjrjrrewhg");
- lt.addLast("fhtjhg");
- Iterator<String> it=lt.iterator();
- while (it.hasNext()) {
- System.out.println(it.next());
-
- }
- }
- }
复制代码
输出结果。为什么是十二个元素啊。我明明只存了八个?
fhtjhg
fhjrjrrewhg
fhrjwhg
feehg
fhtjhg
fhjrjrrewhg
fhrjwhg
feehg
feehg
fhrjwhg
fhjrjrrewhg
fhtjhg
|