一些注意事项

1.数组初始化

int[] a=new int[5];

a[0]默认为0.二维数组也一样。

boolean[] b=new boolean[5];

b[0]默认为false.

2.map如果重复会覆盖

        Map<Integer,Integer> map = new HashMap<Integer,Integer>();
        map.put(1,200);
        System.out.println(map.size());
        map.put(1,300);
        System.out.println(map.size());
        System.out.println(map.get(1));

输出

1
1
300

3.循环

        for(int i=0;i<0;i++){
            System.out.println("ddd");
        }

不会输出。

4.排序

Arrays.sort(数组)

Collections.sort(List)

5.

list.contains(xxx);

注意:时间复杂度O(n)。

map.containsKey(xxx)

时间复杂度小于O(n)。

尽量使用map.containsKey(xxx)。

猜你喜欢

转载自blog.csdn.net/qq_36025975/article/details/80915248