static int | binarySearch(int[] a, int key) 使用二分搜索法来搜索指定的 int 型数组,以获得指定的值。 |
binarySearch
public static int binarySearch(int[] a, int key)
-
使用二分搜索法来搜索指定的 int 型数组,以获得指定的值。必须在进行此调用之前对数组进行排序(通过
sort(int[])
方法)。如果没有对数组进行排序,则结果是不确定的。如果数组包含多个带有指定值的元素,则无法保证找到的是哪一个。
例:import java.util.Arrays;
public class Test {
public static void main(String[] args) {
int[] a = { 1, 2, 34, 5, 6, 534, 6452, 432, 54 };
Arrays.sort(a);// 必须先对a进行排序
int b = Arrays.binarySearch(a, 432);
System.out.println(b);
}
}
输出结果:6
static int | binarySearch(char[] a, char key) 使用二分搜索法来搜索指定的 char 型数组,以获得指定的值。 |
例:import java.util.Arrays;
public class Test {
public static void main(String[] args) {
char[] a = { 'c', 'd', 'm', 'a', 'b', 'l' };
Arrays.sort(a);// 对a进行排序
int b = Arrays.binarySearch(a, 'a');
System.out.println(Arrays.toString(a));
System.out.println(b);
}
}
输出结果:[a, b, c, d, l, m]
0
static int | binarySearch(byte[] a, byte key) 使用二分搜索法来搜索指定的 byte 型数组,以获得指定的值。 | |
static int | binarySearch(byte[] a, int fromIndex, int toIndex, byte key) 使用二分搜索法来搜索指定的 byte 型数组的范围,以获得指定的值。 | |
static int | binarySearch(char[] a, char key) 使用二分搜索法来搜索指定的 char 型数组,以获得指定的值。 | |
static int | binarySearch(char[] a, int fromIndex, int toIndex, char key) 使用二分搜索法来搜索指定的 char 型数组的范围,以获得指定的值。 | |
static int | binarySearch(double[] a, double key) 使用二分搜索法来搜索指定的 double 型数组,以获得指定的值。 | |
static int | binarySearch(double[] a, int fromIndex, int toIndex, double key) 使用二分搜索法来搜索指定的 double 型数组的范围,以获得指定的值。 | |
static int | binarySearch(float[] a, float key) 使用二分搜索法来搜索指定的 float 型数组,以获得指定的值。 | |
static int | binarySearch(float[] a, int fromIndex, int toIndex, float key) 使用二分搜索法来搜索指定的 float 型数组的范围,以获得指定的值。 | |
static int | binarySearch(int[] a, int key) 使用二分搜索法来搜索指定的 int 型数组,以获得指定的值。 | |
static int | binarySearch(int[] a, int fromIndex, int toIndex, int key) 使用二分搜索法来搜索指定的 int 型数组的范围,以获得指定的值。 | |
static int | binarySearch(long[] a, int fromIndex, int toIndex, long key) 使用二分搜索法来搜索指定的 long 型数组的范围,以获得指定的值。 | |
static int | binarySearch(long[] a, long key) 使用二分搜索法来搜索指定的 long 型数组,以获得指定的值。 | |
static int | binarySearch(Object[] a, int fromIndex, int toIndex, Object key) 使用二分搜索法来搜索指定数组的范围,以获得指定对象。 | |
static int | binarySearch(Object[] a, Object key) 使用二分搜索法来搜索指定数组,以获得指定对象。 | |
static int | binarySearch(short[] a, int fromIndex, int toIndex, short key) 使用二分搜索法来搜索指定的 short 型数组的范围,以获得指定的值。 | |
static int | binarySearch(short[] a, short key) 使用二分搜索法来搜索指定的 short 型数组,以获得指定的值。 | |
static
| binarySearch(T[] a, int fromIndex, int toIndex, T key, Comparator<? super T> c) 使用二分搜索法来搜索指定数组的范围,以获得指定对象。 | |
static
| binarySearch(T[] a, T key, Comparator<? super T> c) 使用二分搜索法来搜索指定数组,以获得指定对象。 |
static int[] | copyOf(int[] original, int newLength) 复制指定的数组,截取或用 0 填充(如有必要),以使副本具有指定的长度。 |
copyOf
public static int[] copyOf(int[] original, int newLength)
-
复制指定的数组,截取或用 0 填充(如有必要),以使副本具有指定的长度。对于在原数组和副本中都有效的所有索引,这两个数组将包含相同的值。对于在副本中有效而在原数组无效的所有索引,副本将包含
0。当且仅当指定长度大于原数组的长度时,这些索引存在。
-
original
- 要复制的数组 -
newLength
- 要返回的副本的长度
-
参数:
例:import java.util.Arrays;
public class Test {
public static void main(String[] args) {
int[] a = { 1, 2, 3, 4, 5 };
int[] b = Arrays.copyOf(a, 7);
b[5] = 6;
b[6] = 7;
System.out.println(b.length);
System.out.println(Arrays.toString(b));
}
}
输出结果:7
[1, 2, 3, 4, 5, 6, 7]
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
| copyOf(T[] original, int newLength) 复制指定的数组,截取或用 null 填充(如有必要),以使副本具有指定的长度。 | |
static
| copyOf(U[] original, int newLength, Class<? extends T[]> newType) 复制指定的数组,截取或用 null 填充(如有必要),以使副本具有指定的长度。 |
static int[] | copyOfRange(int[] original, int from, int to) 将指定数组的指定范围复制到一个新数组。 |
public static int[] copyOfRange(int[] original, int from, int to)
-
将指定数组的指定范围复制到一个新数组。该范围的初始索引 (
from) 必须位于 0 和
original.length(包括)之间。
original[from] 处的值放入副本的初始元素中(除非
from == original.length 或
from == to)。原数组中后续元素的值放入副本的后续元素。该范围的最后索引 (
to)(必须大于等于
from)可以大于
original.length,在这种情况下,
0 被放入索引大于等于
original.length - from 的副本的所有元素中。返回数组的长度为
to - from。
-
-
参数:
-
original
- 将要从其复制一个范围的数组 -
from
- 要复制的范围的初始索引(包括) -
to
- 要复制的范围的最后索引(不包括)。(此索引可以位于数组范围之外)。
-
- 例:import java.util.Arrays;
- public class Test {
- public static void main(String[] args) {
-
int[] a = { 1, 2, 3, 4, 5 };
int[] b = Arrays.copyOfRange(a, 1, 5); -
System.out.println(Arrays.toString(b));
} -
}
输出结果:[2, 3, 4, 5]
static boolean | equals(int[] a, int[] a2) 如果两个指定的 int 型数组彼此相等,则返回 true。 |
例:import java.util.Arrays;
public class Test {
public static void main(String[] args) {
int[] a = { 1, 2, 3, 4, 5 };
int[] b = { 2, 3, 5, 4, 1 };
int[] c = { 1, 2, 3, 4, 5 };
System.out.println(Arrays.equals(a, b));
System.out.println(Arrays.equals(a, c));
}
}
输出结果:false
ture
static boolean | equals(boolean[] a, boolean[] a2) 如果两个指定的 boolean 型数组彼此相等,则返回 true。 |
static boolean | equals(byte[] a, byte[] a2) 如果两个指定的 byte 型数组彼此相等,则返回 true。 |
static boolean | equals(char[] a, char[] a2) 如果两个指定的 char 型数组彼此相等,则返回 true。 |
static boolean | equals(double[] a, double[] a2) 如果两个指定的 double 型数组彼此相等,则返回 true。 |
static boolean | equals(float[] a, float[] a2) 如果两个指定的 float 型数组彼此相等,则返回 true。 |
static boolean | equals(int[] a, int[] a2) 如果两个指定的 int 型数组彼此相等,则返回 true。 |
static boolean | equals(long[] a, long[] a2) 如果两个指定的 long 型数组彼此相等,则返回 true。 |
static boolean | equals(Object[] a, Object[] a2) 如果两个指定的 Objects 数组彼此相等,则返回 true。 |
static boolean | equals(short[] a, short[] a2) 如果两个指定的 short 型数组彼此相等,则返回 true。 |
static void | fill(int[] a, int val) 将指定的 int 值分配给指定 int 型数组的每个元素。 |
例:import java.util.Arrays;
public class Test {
public static void main(String[] args) {
int[] a = { 1, 2, 3, 4, 5 };
Arrays.fill(a, 9);
System.out.println(Arrays.toString(a));
}
}
输出结果:[9, 9, 9, 9, 9]
static void | fill(boolean[] a, boolean val) 将指定的 boolean 值分配给指定 boolean 型数组的每个元素。 |
static void | fill(boolean[] a, int fromIndex, int toIndex, boolean val) 将指定的 boolean 值分配给指定 boolean 型数组指定范围中的每个元素。 |
static void | fill(byte[] a, byte val) 将指定的 byte 值分配给指定 byte 节型数组的每个元素。 |
static void | fill(byte[] a, int fromIndex, int toIndex, byte val) 将指定的 byte 值分配给指定 byte 型数组指定范围中的每个元素。 |
static void | fill(char[] a, char val) 将指定的 char 值分配给指定 char 型数组的每个元素。 |
static void | fill(char[] a, int fromIndex, int toIndex, char val) 将指定的 char 值分配给指定 char 型数组指定范围中的每个元素。 |
static void | fill(double[] a, double val) 将指定的 double 值分配给指定 double 型数组的每个元素。 |
static void | fill(double[] a, int fromIndex, int toIndex, double val) 将指定的 double 值分配给指定 double 型数组指定范围中的每个元素。 |
static void | fill(float[] a, float val) 将指定的 float 值分配给指定 float 型数组的每个元素。 |
static void | fill(float[] a, int fromIndex, int toIndex, float val) 将指定的 float 值分配给指定 float 型数组指定范围中的每个元素。 |
static void | fill(int[] a, int val) 将指定的 int 值分配给指定 int 型数组的每个元素。 |
static void | fill(int[] a, int fromIndex, int toIndex, int val) 将指定的 int 值分配给指定 int 型数组指定范围中的每个元素。 |
static void | fill(long[] a, int fromIndex, int toIndex, long val) 将指定的 long 值分配给指定 long 型数组指定范围中的每个元素。 |
static void | fill(long[] a, long val) 将指定的 long 值分配给指定 long 型数组的每个元素。 |
static void | fill(Object[] a, int fromIndex, int toIndex, Object val) 将指定的 Object 引用分配给指定 Object 数组指定范围中的每个元素。 |
static void | fill(Object[] a, Object val) 将指定的 Object 引用分配给指定 Object 数组的每个元素。 |
static void | fill(short[] a, int fromIndex, int toIndex, short val) 将指定的 short 值分配给指定 short 型数组指定范围中的每个元素。 |
static void | fill(short[] a, short val) 将指定的 short 值分配给指定 short 型数组的每个元素。 |
static int | hashCode(int[] a) 基于指定数组的内容返回哈希码。 |
例:import java.util.Arrays;
public class Test {
public static void main(String[] args) {
int[] a = { 1, 2, 3, 4, 5 };
char[] aa={'a','b','c','d'};
int b = Arrays.hashCode(a);
int c=Arrays.hashCode(aa);
System.out.println(b);
System.out.println(c);
}
}
输出结果:29615266
3910595
static int | hashCode(boolean[] a) 基于指定数组的内容返回哈希码。 |
static int | hashCode(byte[] a) 基于指定数组的内容返回哈希码。 |
static int | hashCode(char[] a) 基于指定数组的内容返回哈希码。 |
static int | hashCode(double[] a) 基于指定数组的内容返回哈希码。 |
static int | hashCode(float[] a) 基于指定数组的内容返回哈希码。 |
static int | hashCode(int[] a) 基于指定数组的内容返回哈希码。 |
static int | hashCode(long[] a) 基于指定数组的内容返回哈希码。 |
static int | hashCode(Object[] a) 基于指定数组的内容返回哈希码。 |
static int | hashCode(short[] a) 基于指定数组的内容返回哈希码。 |
static void | sort(byte[] a) 对指定的 byte 型数组按数字升序进行排序。 | |
static void | sort(byte[] a, int fromIndex, int toIndex) 对指定 byte 型数组的指定范围按数字升序进行排序。 | |
static void | sort(char[] a) 对指定的 char 型数组按数字升序进行排序。 | |
static void | sort(char[] a, int fromIndex, int toIndex) 对指定 char 型数组的指定范围按数字升序进行排序。 | |
static void | sort(double[] a) 对指定的 double 型数组按数字升序进行排序。 | |
static void | sort(double[] a, int fromIndex, int toIndex) 对指定 double 型数组的指定范围按数字升序进行排序。 | |
static void | sort(float[] a) 对指定的 float 型数组按数字升序进行排序。 | |
static void | sort(float[] a, int fromIndex, int toIndex) 对指定 float 型数组的指定范围按数字升序进行排序。 | |
static void | sort(int[] a) 对指定的 int 型数组按数字升序进行排序。 | |
static void | sort(int[] a, int fromIndex, int toIndex) 对指定 int 型数组的指定范围按数字升序进行排序。 | |
static void | sort(long[] a) 对指定的 long 型数组按数字升序进行排序。 | |
static void | sort(long[] a, int fromIndex, int toIndex) 对指定 long 型数组的指定范围按数字升序进行排序。 | |
static void | sort(Object[] a) 根据元素的自然顺序对指定对象数组按升序进行排序。 | |
static void | sort(Object[] a, int fromIndex, int toIndex) 根据元素的自然顺序对指定对象数组的指定范围按升序进行排序。 | |
static void | sort(short[] a) 对指定的 short 型数组按数字升序进行排序。 | |
static void | sort(short[] a, int fromIndex, int toIndex) 对指定 short 型数组的指定范围按数字升序进行排序。 | |
static
| sort(T[] a, Comparator<? super T> c) 根据指定比较器产生的顺序对指定对象数组进行排序。 | |
static
| sort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c) 根据指定比较器产生的顺序对指定对象数组的指定范围进行排序。 | |
static String | toString(boolean[] a) 返回指定数组内容的字符串表示形式。 | |
static String | toString(byte[] a) 返回指定数组内容的字符串表示形式。 | |
static String | toString(char[] a) 返回指定数组内容的字符串表示形式。 | |
static String | toString(double[] a) 返回指定数组内容的字符串表示形式。 | |
static String | toString(float[] a) 返回指定数组内容的字符串表示形式。 | |
static String | toString(int[] a) 返回指定数组内容的字符串表示形式。 | |
static String | toString(long[] a) 返回指定数组内容的字符串表示形式。 | |
static String | toString(Object[] a) 返回指定数组内容的字符串表示形式。 | |
static String | toString(short[] a) 返回指定数组内容的字符串表示形式。 |