java一些小优化

1,循环list的优化
    ① for (int i = 0; list != null && i < list.size(); i++) {
       }
    ② if (list != null) {
           for (int i = 0, j = list.size(); i < j; i++) {
           }
        }
  ②的性能比①好。

2,用System.arraycopy代替循环拷贝数组。

    String[] src = new String[]{"1", "2", "3"};
    String[] dest = new String[src.length];
    System.arraycopy(src, 0, dest, 0, src.length);

猜你喜欢

转载自xieyan30.iteye.com/blog/1695132