LinkedList实例

/*  已知数组存放一批QQ号码,QQ号码最长为11位,最短为5位String[] strs = {"12345","67891","12347809933","98765432102","67891","12347809933"}。
    将该数组里面的所有qq号都存放在LinkedList中,将list中重复元素删除,将list中所有元素分别用迭代器和增强for循环打印出来。*/

import java.util.LinkedList;
import java.util.List;

public class Deom03 {
    public static void main(String[] args) {
        String[] strs = {"12345", "67891", "12347809933", "98765432102", "67891", "12347809933"};
        List<String> list = new LinkedList<>();
        for (int i = 0; i < strs.length; i++) {
            list.add(strs[i]);
        }
        for (int i = 0; i < list.size(); i++) {
            for (int i1 = i+1; i1 < list.size(); i1++) {
                String s = list.get(i);
                if (s == list.get(i1)) {
                    list.remove(i1);
                    i1--;
                }

            }
        }
        for (String s : list) {
            System.out.println(s);
        }
    }
}

你可能感兴趣的:(Java)