package com.sf.day16;

import com.sf.day10.integerfacetest01.manyinterface.C;
import org.junit.Test;

import java.nio.channels.Pipe;
import java.util.*;


public class Test01 {

    @Test
    public void t1(){
        LinkedList<String> list = new LinkedList<>();
        list.add("a");
        list.add("b");
        list.add("c");
        //调用addFirst();
        list.addFirst("AAA");
        System.out.println(list);
        list.addLast("WWW");
        System.out.println(list);
        String first = list.getFirst();
        System.out.println(first);
        String last = list.getLast();
        System.out.println(last);
        boolean ee = list.add("ee");
        System.out.println(list.getLast());

        //for循环和foreach循环
        //迭代器


        System.out.println("=========");
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()){
            String next = iterator.next();
            System.out.println(next);
        }
    }

    @Test
    public void t2(){
        Vector<String> vector = new Vector<>();
        vector.add("zhangsan");
        vector.add("lisa");
        vector.add("wangwu");
//        for (int i = 0;i<=vector.size()-1;i++){
//            String s = vector.get(i);
//            System.out.println(s);
//        }
        for (String s : vector) {
            System.out.println(s);
        }

        //迭代器
        Iterator<String> iterator = vector.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }

        //：Enumeration循环:
        Enumeration<String> elements = vector.elements();
        while (elements.hasMoreElements()){
            System.out.println(elements.nextElement());
        }
    }

    @Test
    public void t3(){
        Vector vc = new Vector();
        vc.add("1");
        vc.add("2");
        vc.add("3");
        for (Object o : vc) {
            System.out.println(o);
        }
        vc.set(0,"100");
        for (Object o : vc) {
            System.out.println(o);
        }
    }

    /**
     * hashset
     */
    @Test
    public void t4(){
        HashSet<Integer> hashSet = new HashSet<>();
        hashSet.add(1);
        hashSet.add(2);
        hashSet.add(3);
        hashSet.add(3);  //去重
        System.out.println(hashSet);


        /**
         * 去重
         */
        HashSet<ArrayList<String>> arrayLists1 = new HashSet<>();
        ArrayList<String> strings = new ArrayList<>();
        ArrayList<String> strings2 = new ArrayList<>();
        strings.add("zhangsan");
        strings.add("lisa");

        strings2.add("zhangsan");
        strings2.add("lisa");
        arrayLists1.add(strings);
        arrayLists1.add(strings2);

        System.out.println(arrayLists1);


    }


    @Test
    public void t5(){
        /**
         * 创建一个arraylist集合<Integer>   {1,2,3,4,5,6,6,7,7,8,8,9}  如何实现快速去重
         * 将list集合转换成set集合
         */
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(3);
        list.add(3);
        list.add(4);
        list.add(5);
        HashSet<Integer> hashSet = new HashSet<>(list);
        System.out.println(hashSet);

    }
}
