Collection类学习笔记

 

binarySearch原理:

 

public static index halfSearch(List<String> list, String key)

{

int max,min,mid;

max = list.size()-1;

min = 0;

while(min<=max)

{

        mid = (max+min) >>1;

        String str = list.get(mid);

        int num = str.compareTo(key);

        if(num > 0)

                max = mid – 1;

        else if(num < 0)

                min = min + 1;

        return min;//如果是Collections.binarySearch(),它是在min后面的位置-(接入点) - 1

}

}

--------------------

Collections.fill(list, “pp”);

将集合中的元素全部替换成为pp

--------------------

Collections.replaceAll(list, “oldValue”, “newValue”);

相同于:

list.set(index, “newValue”);

----------------------

Collections.reverse(list);

----------------------

Collections.swap(list, 1, 2);//角标1、角标2对换

----------------------

Collections.shuffle(list);//随机排列list

----------------------

你可能感兴趣的:(Collection)