浏览 1847 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (1) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-01-16
最后修改:2009-02-15
public static int binarySearch(byte[] a, byte key) Searches the specified array of bytes for the specified value using the binary search algorithm. 这个方法查询key元素值在a数组中出现的索引;如果a数组不包含key元素值,则返回-1.调用该方法时要求数组中元素已经按升序排列,这样才能得到正确结果。 Returns: the index of the search key, if it is contained in the list; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the list: the index of the first element greater than the key, or list.size() if all elements in the list are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found. type[] copyOf(type[] original,int newLength): 这个方法将会把original数组复制成一个新数组,其中length是新数组的长度。如果length小于original数组的长度,则新数组就是原数组的前面length个元素;如果length大于original数组的长度,则新数组的前面元素就是原数组的所个元素,后面补充0(数值型)、false(布尔型)或者null(引用型)。 public static boolean equals(byte[] a, byte[] a2) Returns true if the two specified arrays of bytes are equal to one another------如果a数组和a2数组的长度相等,而且a数组和a2数组的数组元素也一一相同,该方法将返回true public static void fill(byte[] a, byte val) Assigns the specified byte value to each element of the specified array of bytes. public static void fill(byte[] a, int fromIndex, int toIndex, byte val) Assigns the specified byte value to each element of the specified range of the specified array of bytes. public static void sort(byte[] a) Sorts the specified array of bytes into ascending numerical order. 举例: import java.util.Arrays; public class ArrayDemo1 { public static void main(String args[]) { int[] a1 = new int[10]; int[] a2 = new int[10]; Arrays.fill(a1, 47); Arrays.fill(a2, 47); System.out.println(Arrays.equals(a1, a2)); a2[3]=11; a2[2]=9; System.out.println(Arrays.equals(a1, a2)); Arrays.sort(a2); System.out.println(Arrays.binarySearch(a2, 11)); } } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2009-01-16
嗯,谢谢谢谢旋
|
|
返回顶楼 | |