国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

JAVA基礎學習day17--集合工具類-Collections

2019-11-14 15:33:19
字體:
來源:轉載
供稿:網友

一、Collection簡述

1.1、Collection與Collections的區別

Collections是集合的靜態工具類

Collection:是集合的頂級接口

 

二、Sort

2.1、sort

 

package com.pb.sort.demo1;import java.util.ArrayList;import java.util.Collections;/** * 對字符串進行自然排序 * */public class SortDemo1 {    public static void main(String[] args) {        ArrayList<String> list=new ArrayList<String>();        list.add("zfdsfd");        list.add("dee");        list.add("z");        list.add("fsdfdsfd");        list.add("abd");        list.add("z");        System.out.list);        //自然排序        Collections.sort(list);        System.out.println("排序后"+list);    }}

示例二、

 

三、max

3.1、max

 

 

對象求最大值:

package com.pb.sort.demo1;import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;/** * 求對象的最大值: *1.類本身實現比較功能或者使用比較器 *2.按對象的age求最大值 */class Person{    private String name;    private int age;    public Person(String name, int age) {        super();        this.name = name;        this.age = age;    }    public Person() {        super();        // TODO Auto-generated constructor stub    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public int getAge() {        return age;    }    public void setAge(int age) {        this.age = age;    }    }public class MaxPersonTest {    public static void main(String[] args) {        ArrayList<Person> list =new ArrayList<Person>();        list.add(new Person("lisi005",34));        list.add(new Person("lisi002",16));        list.add(new Person("lisi009",16));        list.add(new Person("lisi001",23));        System.out.println("未排序::");        sop(list);        //排序        Collections.sort(list,new PersonCom());        System.out.println("排序后:");        sop(list);        Person maxPerson=Collections.max(list, new PersonCom());        System.out.println("年齡最大的人:"+maxPerson.getName()+"..."+maxPerson.getAge());    }    public static void sop(ArrayList<Person> list){        for(Person p:list){            System.out.println(p.getName()+"..."+p.getAge());        }    }}class PersonCom implements Comparator<Person>{    public int compare(Person p1,Person p2){        int num=new Integer(p1.getAge()).compareTo(new Integer(p2.getAge()));        if(num==0){            return p1.getName().compareTo(p2.getName());        }        return num;    }}//結果:未排序::lisi005...34lisi002...16lisi009...16lisi001...23排序后:lisi002...16lisi009...16lisi001...23lisi005...34年齡最大的人:lisi005...34

 

四、binarySearch

 

4.1、binarySearch

用二分搜索法搜索指定列表,以獲得指定對象。在進行此調用之前,必須根據列表元素的自然順序對列表進行升序排序(通過 sort(List) 方法)。如果沒有對列表進行排序,則結果是不確定的。如果列表包含多個等于指定對象的元素,則無法保證找到的是哪一個。

參數:list - 要搜索的列表。key - 要搜索的鍵。返回:如果搜索鍵包含在列表中,則返回搜索鍵的索引;否則返回 (-(插入點) - 1)插入點 被定義為將鍵插入列表的那一點:即第一個大于此鍵的元素索引;如果列表中的所有元素都小于指定的鍵,則為 list.size()。注意,這保證了當且僅當此鍵被找到時,返回的值將 >= 0

package com.pb.sort.demo1;import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.List;public class BinarSearchDemo {    public static void main(String[] args) {        ArrayList<String> list = new ArrayList<String>();        list.add("zfdsfd");        list.add("dee");        list.add("z");        list.add("fsdfdsfd");        list.add("abd");        list.add("zf");        Collections.sort(list);        System.out.println(list);        int index = Collections.binarySearch(list, "dee");// 1        System.out.println("index=" + index);        int index1 = Collections.binarySearch(list, "deed");        System.out.println("index1=" + index1);// 沒有返回-(插入點)一1 -(2)-1 結果-3        // 測試        int index2 = halfSearch(list, "z");        System.out.println("index2=" + index2);// 3        int index3 = halfSearch(list, "zdd");        System.out.println("index3=" + index3);// -5        // 測試        int index4 = halfSearch2(list, "z",new MyComp());        System.out.println("index4=" + index4);//        int index5 = halfSearch2(list, "zdd",new MyComp());        System.out.println("index5=" + index5);//    }    // 手動實現二分法查找    public static int halfSearch(List<String> list, String key) {        int max = list.size() - 1;        int min = 0;        int mid;        while (min <= max) {            mid = (min + max) >>> 1; // 除2            String str = list.get(mid); // 中間值            int num = str.compareTo(key);            if (num > 0) {                max = mid - 1;            } else if (num < 0) {                min = mid + 1;            } else {                return mid;            }        }        return -min - 1; // 返回-(插入點)-1    }    // 手動實現二分法查找,添加比較器    public static int halfSearch2(List<String> list, String key, Comparator<String> com) {        int max = list.size() - 1;        int min = 0;        int mid;        while (min <= max) {            mid = (min + max) >>> 1; // 除2            String str = list.get(mid); // 中間值            int num = com.compare(str, key);            if (num > 0) {                max = mid - 1;            } else if (num < 0) {                min = mid + 1;            } else {                return mid;            }        }        return -min - 1; // 返回-(插入點)-1    }}class MyComp implements Comparator<String>{    @Override    public int compare(String s1, String s2) {        int num=new Integer(s2.length()).compareTo(new Integer(s1.length()));        if(num==0){            return s1.compareTo(s1);        }        return num;    }    }

[abd, dee, fsdfdsfd, z, zf, zfdsfd]
index=1
index1=-3
index2=3
index3=-5
index4=-7
index5=-4

 

 

 

五、fill

5.1、fill

使用指定元素替換指定列表中的所有元素。

此方法以線性時間運行。

 

參數:
list - 使用指定元素填充的列表。
obj - 用來填充指定列表的元素。 

示例二、

 

六、replaceAll

6.1、replaceAll

 

 

 

 

七、reverse與reverSEOrder

 

7.1、reverse

package com.pb.sort.demo1;import java.util.ArrayList;import java.util.Collections;public class ReplaceAllDemo {    public static void main(String[] args) {        ArrayList<String> list=new ArrayList<String>();        list.add("zfdsfd");        list.add("dee");        list.add("z");        list.add("fsdfdsfd");        list.add("abd");        list.add("zb");        Collections.reverse(list);        System.out.println(list);    }}

7.2、reverseOrder

返回一個比較器,它強行逆轉實現了 Comparable 接口的對象 collection 的自然順序。(自然順序是通過對象自身的 compareTo 方法強行排序的。)此方法允許使用單個語句,以逆自然順序對實現了 Comparable 接口的對象 collection(或數組)進行排序(或維護)。例如,假設 a 是一個字符串數組。那么:

                Arrays.sort(a, Collections.reverseOrder());

將按照逆字典(字母)順序對數組進行排序。

返回的比較器是可序列化的。

 

 

 

返回:
返回一個比較器,它強行逆轉實現了 Comparable 接口的對象 collection 的自然順序
package com.pb.sort.demo1;import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.TreeSet;public class ReverseOrder {    public static void main(String[] args) {        ArrayList<String> list=new ArrayList<String>();        list.add("bdc");        list.add("uioew");        list.add("a");        list.add("hg");        Collections.sort(list);        System.out.println(list);        Collections.sort(list, Collections.reverseOrder());        System.out.println(list);        TreeSet<String> ts=new TreeSet<String>(Collections.reverseOrder(new StrLencom()));        ts.add("cccccc");        ts.add("dddd");        ts.add("a");        ts.add("hh");        System.out.println(ts);    }}class StrLencom implements Comparator<String>{    @Override    public int compare(String s1, String s2) {        int num=new Integer(s1.length()).compareTo(new Integer(s2.length()));        if(num==0){            return s1.compareTo(s2);        }        return num;    }    }//結果:[a, bdc, hg, uioew][uioew, hg, bdc, a][cccccc, dddd, hh, a]

 

八、swap

8.1、swap

package com.pb.sort.demo1;import java.util.ArrayList;import java.util.Collections;public class SwapDemo {    public static void main(String[] args) {        ArrayList<String> list=new ArrayList<String>();        list.add("bdc");        list.add("uioew");        list.add("a");        list.add("hg");        System.out.println(list);        //交換指定下位的2個元素        Collections.swap(list, 2, 0);        System.out.println(list);    }}//結果[bdc, uioew, a, hg][a, uioew, bdc, hg]

 

 

 

 

九、shuffle

9.1、shuffle

使用默認隨機源對指定列表進行置換。所有置換發生的可能性都是大致相等的

package com.pb.sort.demo1;import java.util.ArrayList;import java.util.Collections;import java.util.Random;public class SwapDemo {    public static void main(String[] args) {        ArrayList<String> list=new ArrayList<String>();        list.add("bdc");        list.add("uioew");        list.add("a");        list.add("hg");        System.out.println(list);        //交換指定下位的2個元素        Collections.shuffle(list);        System.out.println(list);        Collections.shuffle(list,new Random(list.size()+1));        System.out.println(list);    }}

第二,第三都隨機的每次運行不一樣

[bdc, uioew, a, hg][hg, a, bdc, uioew][uioew, hg, a, bdc]

 

 

 

十、Arrays

10.1、Arrays

操作數組的靜態工具類,和使用Collection方法一樣

方法摘要
static
<T> List<T>
asList(T... a)
返回一個受指定數組支持的固定大小的列表。
static intbinarySearch(byte[] a, byte key)
使用二分搜索法來搜索指定的 byte 型數組,以獲得指定的值。
static intbinarySearch(byte[] a, int fromIndex, int toIndex, byte key)
使用二分搜索法來搜索指定的 byte 型數組的范圍,以獲得指定的值。
static intbinarySearch(char[] a, char key)
使用二分搜索法來搜索指定的 char 型數組,以獲得指定的值。
static intbinarySearch(char[] a, int fromIndex, int toIndex, char key)
使用二分搜索法來搜索指定的 char 型數組的范圍,以獲得指定的值。
static intbinarySearch(double[] a, double key)
使用二分搜索法來搜索指定的 double 型數組,以獲得指定的值。
static intbinarySearch(double[] a, int fromIndex, int toIndex, double key)
使用二分搜索法來搜索指定的 double 型數組的范圍,以獲得指定的值。
static intbinarySearch(float[] a, float key)
使用二分搜索法來搜索指定的 float 型數組,以獲得指定的值。
static intbinarySearch(float[] a, int fromIndex, int toIndex, float key)
使用二分搜索法來搜索指定的 float 型數組的范圍,以獲得指定的值。
static intbinarySearch(int[] a, int key)
使用二分搜索法來搜索指定的 int 型數組,以獲得指定的值。
static intbinarySearch(int[] a, int fromIndex, int toIndex, int key)
使用二分搜索法來搜索指定的 int 型數組的范圍,以獲得指定的值。
static intbinarySearch(long[] a, int fromIndex, int toIndex, long key)
使用二分搜索法來搜索指定的 long 型數組的范圍,以獲得指定的值。
static intbinarySearch(long[] a, long key)
使用二分搜索法來搜索指定的 long 型數組,以獲得指定的值。
static intbinarySearch(Object[] a, int fromIndex, int toIndex, Object key)
使用二分搜索法來搜索指定數組的范圍,以獲得指定對象。
static intbinarySearch(Object[] a, Object key)
使用二分搜索法來搜索指定數組,以獲得指定對象。
static intbinarySearch(short[] a, int fromIndex, int toIndex, short key)
使用二分搜索法來搜索指定的 short 型數組的范圍,以獲得指定的值。
static intbinarySearch(short[] a, short key)
使用二分搜索法來搜索指定的 short 型數組,以獲得指定的值。
static
<T> int
binarySearch(T[] a, int fromIndex, int toIndex, T key, Comparator<? super T> c)
使用二分搜索法來搜索指定數組的范圍,以獲得指定對象。
static
<T> int
binarySearch(T[] a, T key, Comparator<? super T> c)
使用二分搜索法來搜索指定數組,以獲得指定對象。
static boolean[]copyOf(boolean[] original, int newLength)
復制指定的數組,截取或用 false 填充(如有必要),以使副本具有指定的長度。
static byte[]copyOf(byte[] original, int newLength)
復制指定的數組,截取或用 0 填充(如有必要),以使副本具有指定的長度。
static char[]copyOf(char[] original, int newLength)
復制指定的數組,截取或用 null 字符填充(如有必要),以使副本具有指定的長度。
static double[]copyOf(double[] original, int newLength)
復制指定的數組,截取或用 0 填充(如有必要),以使副本具有指定的長度。
static float[]copyOf(float[] original, int newLength)
復制指定的數組,截取或用 0 填充(如有必要),以使副本具有指定的長度。
static int[]copyOf(int[] original, int newLength)
復制指定的數組,截取或用 0 填充(如有必要),以使副本具有指定的長度。
static long[]copyOf(long[] original, int newLength)
復制指定的數組,截取或用 0 填充(如有必要),以使副本具有指定的長度。
static short[]copyOf(short[] original, int newLength)
復制指定的數組,截取或用 0 填充(如有必要),以使副本具有指定的長度。
static
<T> T[]
copyOf(T[] original, int newLength)
復制指定的數組,截取或用 null 填充(如有必要),以使副本具有指定的長度。
static
<T,U> T[]
copyOf(U[] original, int newLength, Class<? extends T[]> newType)
復制指定的數組,截取或用 null 填充(如有必要),以使副本具有指定的長度。
static boolean[]copyOfRange(boolean[] original, int from, int to)
將指定數組的指定范圍復制到一個新數組。
static byte[]copyOfRange(byte[] original, int from, int to)
將指定數組的指定范圍復制到一個新數組。
static char[]copyOfRange(char[] original, int from, int to)
將指定數組的指定范圍復制到一個新數組。
static double[]copyOfRange(double[] original, int from, int to)
將指定數組的指定范圍復制到一個新數組。
static float[]copyOfRange(float[] original, int from, int to)
將指定數組的指定范圍復制到一個新數組。
static int[]copyOfRange(int[] original, int from, int to)
將指定數組的指定范圍復制到一個新數組。
static long[]copyOfRange(long[] original, int from, int to)
將指定數組的指定范圍復制到一個新數組。
static short[]copyOfRange(short[] original, int from, int to)
將指定數組的指定范圍復制到一個新數組。
static
<T> T[]
copyOfRange(T[] original, int from, int to)
將指定數組的指定范圍復制到一個新數組。
static
<T,U> T[]
copyOfRange(U[] original, int from, int to, Class<? extends T[]> newType)
將指定數組的指定范圍復制到一個新數組。
static booleandeepEquals(Object[] a1, Object[] a2)
如果兩個指定數組彼此是深層相等 的,則返回 true
static intdeepHashCode(Object[] a)
基于指定數組的“深層內容”返回哈希碼。
static StringdeepToString(Object[] a)
返回指定數組“深層內容”的字符串表示形式。
static booleanequals(boolean[] a, boolean[] a2)
如果兩個指定的 boolean 型數組彼此相等,則返回 true
static booleanequals(byte[] a, byte[] a2)
如果兩個指定的 byte 型數組彼此相等,則返回 true
static booleanequals(char[] a, char[] a2)
如果兩個指定的 char 型數組彼此相等,則返回 true
static booleanequals(double[] a, double[] a2)
如果兩個指定的 double 型數組彼此相等,則返回 true
static booleanequals(float[] a, float[] a2)
如果兩個指定的 float 型數組彼此相等,則返回 true
static booleanequals(int[] a, int[] a2)
如果兩個指定的 int 型數組彼此相等,則返回 true
static booleanequals(long[] a, long[] a2)
如果兩個指定的 long 型數組彼此相等,則返回 true
static booleanequals(Object[] a, Object[] a2)
如果兩個指定的 Objects 數組彼此相等,則返回 true
static booleanequals(short[] a, short[] a2)
如果兩個指定的 short 型數組彼此相等,則返回 true
static voidfill(boolean[] a, boolean val)
將指定的 boolean 值分配給指定 boolean 型數組的每個元素。
static voidfill(boolean[] a, int fromIndex, int toIndex, boolean val)
將指定的 boolean 值分配給指定 boolean 型數組指定范圍中的每個元素。
static voidfill(byte[] a, byte val)
將指定的 byte 值分配給指定 byte 節型數組的每個元素。
static voidfill(byte[] a, int fromIndex, int toIndex, byte val)
將指定的 byte 值分配給指定 byte 型數組指定范圍中的每個元素。
static voidfill(char[] a, char val)
將指定的 char 值分配給指定 char 型數組的每個元素。
static voidfill(char[] a, int fromIndex, int toIndex, char val)
將指定的 char 值分配給指定 char 型數組指定范圍中的每個元素。
static voidfill(double[] a, double val)
將指定的 double 值分配給指定 double 型數組的每個元素。
static voidfill(double[] a, int fromIndex, int toIndex, double val)
將指定的 double 值分配給指定 double 型數組指定范圍中的每個元素。
static voidfill(float[] a, float val)
將指定的 float 值分配給指定 float 型數組的每個元素。
static voidfill(float[] a, int fromIndex, int toIndex, float val)
將指定的 float 值分配給指定 float 型數組指定范圍中的每個元素。
static voidfill(int[] a, int val)
將指定的 int 值分配給指定 int 型數組的每個元素。
static voidfill(int[] a, int fromIndex, int toIndex, int val)
將指定的 int 值分配給指定 int 型數組指定范圍中的每個元素。
static voidfill(long[] a, int fromIndex, int toIndex, long val)
將指定的 long 值分配給指定 long 型數組指定范圍中的每個元素。
static voidfill(long[] a, long val)
將指定的 long 值分配給指定 long 型數組的每個元素。
static voidfill(Object[] a, int fromIndex, int toIndex, Object val)
將指定的 Object 引用分配給指定 Object 數組指定范圍中的每個元素。
static voidfill(Object[] a, Object val)
將指定的 Object 引用分配給指定 Object 數組的每個元素。
static voidfill(short[] a, int fromIndex, int toIndex, short val)
將指定的 short 值分配給指定 short 型數組指定范圍中的每個元素。
static voidfill(short[] a, short val)
將指定的 short 值分配給指定 short 型數組的每個元素。
static inthashCode(boolean[] a)
基于指定數組的內容返回哈希碼。
static inthashCode(byte[] a)
基于指定數組的內容返回哈希碼。
static inthashCode(char[] a)
基于指定數組的內容返回哈希碼。
static inthashCode(double[] a)
基于指定數組的內容返回哈希碼。
static inthashCode(float[] a)
基于指定數組的內容返回哈希碼。
static inthashCode(int[] a)
基于指定數組的內容返回哈希碼。
static inthashCode(long[] a)
基于指定數組的內容返回哈希碼。
static inthashCode(Object[] a)
基于指定數組的內容返回哈希碼。
static inthashCode(short[] a)
基于指定數組的內容返回哈希碼。
static voidsort(byte[] a)
對指定的 byte 型數組按數字升序進行排序。
static voidsort(byte[] a, int fromIndex, int toIndex)
對指定 byte 型數組的指定范圍按數字升序進行排序。
static voidsort(char[] a)
對指定的 char 型數組按數字升序進行排序。
static voidsort(char[] a, int fromIndex, int toIndex)
對指定 char 型數組的指定范圍按數字升序進行排序。
static voidsort(double[] a)
對指定的 double 型數組按數字升序進行排序。
static voidsort(double[] a, int fromIndex, int toIndex)
對指定 double 型數組的指定范圍按數字升序進行排序。
static voidsort(float[] a)
對指定的 float 型數組按數字升序進行排序。
static voidsort(float[] a, int fromIndex, int toIndex)
對指定 float 型數組的指定范圍按數字升序進行排序。
static voidsort(int[] a)
對指定的 int 型數組按數字升序進行排序。
static voidsort(int[] a, int fromIndex, int toIndex)
對指定 int 型數組的指定范圍按數字升序進行排序。
static voidsort(long[] a)
對指定的 long 型數組按數字升序進行排序。
static voidsort(long[] a, int fromIndex, int toIndex)
對指定 long 型數組的指定范圍按數字升序進行排序。
static voidsort(Object[] a)
根據元素的自然順序對指定對象數組按升序進行排序。
static voidsort(Object[] a, int fromIndex, int toIndex)
根據元素的自然順序對指定對象數組的指定范圍按升序進行排序。
static voidsort(short[] a)
對指定的 short 型數組按數字升序進行排序。
static voidsort(short[] a, int fromIndex, int toIndex)
對指定 short 型數組的指定范圍按數字升序進行排序。
static
<T> void
sort(T[] a, Comparator<? super T> c)
根據指定比較器產生的順序對指定對象數組進行排序。
static
<T> void
sort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c)
根據指定比較器產生的順序對指定對象數組的指定范圍進行排序。
static StringtoString(boolean[] a)
返回指定數組內容的字符串表示形式。
static StringtoString(byte[] a)
返回指定數組內容的字符串表示形式。
static StringtoString(char[] a)
返回指定數組內容的字符串表示形式。
static StringtoString(double[] a)
返回指定數組內容的字符串表示形式。
static StringtoString(float[] a)
返回指定數組內容的字符串表示形式。
static StringtoString(int[] a)
返回指定數組內容的字符串表示形式。
static StringtoString(long[] a)
返回指定數組內容的字符串表示形式。
static StringtoString(Object[] a)
返回指定數組內容的字符串表示形式。
static StringtoString(short[] a)
返回指定數組內容的字符串表示形式。

十一、數組和集合相互轉換

11.1、數組轉集合

數組轉集合不可以用集合的:增加,刪除

 

package com.pb.sort.demo1;import java.util.Arrays;import java.util.List;public class ArrayToList {    public static void main(String[] args) {        String[] arr={"bde","aab","bc","dd"};        //轉換集合 數組轉集合不可以用集合的:增加,刪除        List<String> list=Arrays.asList(arr);        list.set(2, "hello");        System.out.println(list.contains("dd"));        System.out.println(list);    }}

 

如果數組中的元素都是對象String,對象,那么變成集合時,數組中的元素就直接轉成集合中的元素

如果數組中的元素都是基本數組類型,那么會將該數組作為集合的中元素存在

 

 

十二、增強for循環

12.1、增強for循環

 

 

package com.pb.sort.demo1;import java.util.ArrayList;import java.util.HashMap;import java.util.HashSet;import java.util.Map;import java.util.Set;public class ForEachDemo {    public static void main(String[] args) {        ArrayList<String> list=new ArrayList<String>();        list.add("zfdsfd");        list.add("dee");        list.add("z");        list.add("fsdfdsfd");        list.add("abd");        list.add("z");        for(String s:list){            System.out.println(s);        }        Set<Integer> set=new HashSet<Integer>();        set.add(3);        set.add(2);        set.add(2);        set.add(5);        for(Integer i:set){            System.out.println(i);        }        Map<String,Integer> map=new HashMap<String,Integer>();        map.put("001", 3);        map.put("002", 5);        map.put("006", 1);        map.put("003", 113);        for(String s:map.keySet()){            System.out.println(s+".."+map.get(s));        }        for(Map.Entry<String, Integer> me:map.entrySet()){            System.out.println(me.getKey()+"..."+me.getValue());        }    }    }

 

十三、可變參數

13.1、可變參數

 

package com.pb.sort.demo1;public class ParamsDemo {    public static void main(String[] args) {        show();        show(3,4,5);        show(8,9,10,99);    }    public static void show(int ...arr){//..可變參數自動封裝為數組        System.out.println("長度"+arr.length);        for(int i:arr){            System.out.println(i+"...");        }            }}

 

長度0長度33...4...5...長度48...9...10...99...

可變參數類型必須為同一類型

 

package com.pb.sort.demo1;public class ParamsDemo {    public static void main(String[] args) {        show("hello");        show("java",3,4,5);        show("world",8,9,10,99);    }    public static void show(String str,int ...arr){//..可變參數自動封裝為數組 可變參數要定義在參數列表 的后面        System.out.println("長度"+arr.length);        for(int i:arr){            System.out.println(i+"...");        }            }}

 

 

十四、靜態導入

14.1、靜態導入

static import靜態導入

當方法重名里:指定具備所屬的對象或者類

 

package com.pb.sort.demo1;import static java.util.Arrays.*; //導入Arrays類中的方法可以直接使用方法import java.util.Arrays;import static java.lang.System.*;public class StaticImportDemo extends Object {    public static void main(String[] args) {        String [] arr={"abc","b","a","ab","d"};        //直接使用排序方法        sort(arr);        int index=binarySearch(arr, "d");        System.out.println("index="+index);        //靜態導入了System.可以直接使用        out.println(Arrays.toString(arr)); //顯示的輸入使用哪個類的哪個方法            }}

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 郎溪县| 农安县| 利津县| 凌源市| 临城县| 彝良县| 绥芬河市| 启东市| 蚌埠市| 河北区| 稷山县| 五河县| 澎湖县| 枞阳县| 彰武县| 南木林县| 灵武市| 改则县| 即墨市| 宜兰县| 宁津县| 永年县| 惠水县| 台安县| 邓州市| 苏州市| 蒙山县| 府谷县| 库伦旗| 宁安市| 盐城市| 九江县| 衡南县| 丹江口市| 潜江市| 扎鲁特旗| 榕江县| 玉环县| 密云县| 丹巴县| 丹凤县|