07-Lists

单列集合的工具类

 

 

        // Lists
        // 创建集合
        List<String> list1 = Lists.newArrayList();
        List<String> list2 = Lists.newArrayListWithCapacity(8);
        List<String> list3 = Lists.newArrayListWithExpectedSize(8);

        // 集合分片
        List<Integer> list4 = Lists.newArrayList(1, 2, 3, 4, 5);
        // [[1, 2], [3, 4], [5]]
        List<List<Integer>> partition = Lists.partition(list4, 2);
        System.out.println(partition);

        //新建集合
        String str1 = " I love you";
        String[] str2 = {" I like you", "I miss you"};
        List<String> list5 = Lists.asList(str1, str2);
        // [ I love you,  I like you, I miss you]
        System.out.println(list5);
        str2[1] = " I hate you";
        // [ I love you,  I like you,  I hate you] 都会变化
        System.out.println(list5);
        //反转集合中元素
        // [ I hate you,  I like you,  I love you]
        List<String> list6 = Lists.reverse(list5);
        System.out.println(list6);

 

上一篇:[CISCN 2019 初赛]Love Math


下一篇:Codeforces 1523D Love-Hate(随机化算法,sos dp)