Arrays中常用的几个静态方法:
1、二分查找,是静态方法,且不需排序,返回下标。
static int | binarySearch(byte[] a, byte key)
Searches the specified array of bytes for the specified value using the binary search algorithm.
|
static int | binarySearch(char[] a, char key)
Searches the specified array of chars for the specified value using the binary search algorithm.
|
static int | binarySearch(double[] a, double key)
Searches the specified array of doubles for the specified value using the binary search algorithm.
|
static int | binarySearch(float[] a, float key)
Searches the specified array of floats for the specified value using the binary search algorithm.
|
static int | binarySearch(int[] a, int key)
Searches the specified array of ints for the specified value using the binary search algorithm.
|
static int | binarySearch(long[] a, long key)
Searches the specified array of longs for the specified value using the binary search algorithm.
|
static int | binarySearch(Object[] a, Object key)
Searches the specified array for the specified object using the binary search algorithm.
|
static int | binarySearch(short[] a, int fromIndex, int toIndex, short key)
Searches a range of the specified array of shorts for the specified value using the binary search algorithm.
|
static int | binarySearch(short[] a, short key)
Searches the specified array of shorts for the specified value using the binary search algorithm.
|
2、复制数组,静态方法;
static boolean[] | copyOf(boolean[] original, int newLength)
Copies the specified array, truncating or padding with
false (if necessary) so the copy has the specified length.
|
static byte[] | copyOf(byte[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
|
static char[] | copyOf(char[] original, int newLength)
Copies the specified array, truncating or padding with null characters (if necessary) so the copy has the specified length.
|
static double[] | copyOf(double[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
|
static float[] | copyOf(float[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
|
static int[] | copyOf(int[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
|
static long[] | copyOf(long[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
|
static short[] | copyOf(short[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
|
static <T> T[] | copyOf(T[] original, int newLength)
Copies the specified array, truncating or padding with nulls (if necessary) so the copy has the specified length.
|
static <T,U> T[] | copyOf(U[] original, int newLength, Class<? extends T[]> newType)
Copies the specified array, truncating or padding with nulls (if necessary) so the copy has the specified length.
|
static boolean | equals(boolean[] a, boolean[] a2)
Returns
true if the two specified arrays of booleans are
equal to one another.
|
static boolean | equals(byte[] a, byte[] a2)
Returns
true if the two specified arrays of bytes are
equal to one another.
|
static boolean | equals(char[] a, char[] a2)
Returns
true if the two specified arrays of chars are
equal to one another.
|
static boolean | equals(double[] a, double[] a2)
Returns
true if the two specified arrays of doubles are
equal to one another.
|
static boolean | equals(float[] a, float[] a2)
Returns
true if the two specified arrays of floats are
equal to one another.
|
static boolean | equals(int[] a, int[] a2)
Returns
true if the two specified arrays of ints are
equal to one another.
|
static boolean | equals(long[] a, long[] a2)
Returns
true if the two specified arrays of longs are
equal to one another.
|
static boolean | equals(Object[] a, Object[] a2)
Returns
true if the two specified arrays of Objects are
equal to one another.
|
static boolean | equals(short[] a, short[] a2)
Returns
true if the two specified arrays of shorts are
equal to one another.
|
static void | fill(boolean[] a, boolean val)
Assigns the specified boolean value to each element of the specified array of booleans.
|
static void | sort(byte[] a)
Sorts the specified array into ascending numerical order.
|
static void | sort(byte[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending order.
|
static void | sort(char[] a)
Sorts the specified array into ascending numerical order.
|
static void | sort(char[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending order.
|
static void | sort(double[] a)
Sorts the specified array into ascending numerical order.
|
static void | sort(double[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending order.
|
static void | sort(float[] a)
Sorts the specified array into ascending numerical order.
|
static void | sort(float[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending order.
|
static void | sort(int[] a)
Sorts the specified array into ascending numerical order.
|
static void | sort(int[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending order.
|
static void | sort(long[] a)
Sorts the specified array into ascending numerical order.
|
static void | sort(long[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending order.
|
static void | sort(Object[] a)
Sorts the specified array of objects into ascending order, according to the
natural ordering of its elements.
|
static void | sort(Object[] a, int fromIndex, int toIndex)
Sorts the specified range of the specified array of objects into ascending order, according to the
natural ordering of its elements.
|
static void | sort(short[] a)
Sorts the specified array into ascending numerical order.
|
static void | sort(short[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending order.
|
static String | toString(boolean[] a)
Returns a string representation of the contents of the specified array.
|
static String | toString(byte[] a)
Returns a string representation of the contents of the specified array.
|
static String | toString(char[] a)
Returns a string representation of the contents of the specified array.
|
static String | toString(double[] a)
Returns a string representation of the contents of the specified array.
|
static String | toString(float[] a)
Returns a string representation of the contents of the specified array.
|
static String | toString(int[] a)
Returns a string representation of the contents of the specified array.
|
static String | toString(long[] a)
Returns a string representation of the contents of the specified array.
|
static String | toString(Object[] a)
Returns a string representation of the contents of the specified array.
|
static String | toString(short[] a)
Returns a string representation of the contents of the specified array.
|
String[] stringArray = { "a","b", "c", "d", "e" };
ArrayList<String> arrayList = new ArrayList<String>(Arrays.asList(stringArray));
System.out.println(arrayList);
注意:
Integer[] data= new Integer[] {1,2,3};
ArrayList<Integer> dataList =new ArrayList<Integer>(Arrays.asList(data));
要想把数组转化为List,数组应该是类类型数组,基本数据构成的数组不行。还有就是Arrays.asList(data)返回的是List因此最好是使用上面的形式。
7、数组中没有contains方法;
8、String中有contains方法;是对象的方法。