全部是静态方法
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));
}
}
分享到:
相关推荐
SWIFTStandards Category 4 Collections & Cash Letters Swift报文标准,目录4
presentation at St. Louis Java User Group
C# Lab Arrays and Collections
本文详细讲解了java中Collection与Collections,Array与Arrays的区别。
commons-collections-20040616.jar, commons-collections-3.2-osgi.jar, commons-collections-3.2-sources.jar, commons-collections-3.2.1.jar, commons-collections-3.2.2-javadoc.jar, commons-collections-3.2.2...
主要介绍了Java Arrays.sort和Collections.sort排序实现原理解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
赠送jar包:commons-collections-3.2.2.jar; 赠送原API文档:commons-collections-3.2.2-javadoc.jar; 赠送源代码:commons-collections-3.2.2-sources.jar; 赠送Maven依赖信息文件:commons-collections-3.2.2....
赠送jar包:commons-collections4-4.1.jar; 赠送原API文档:commons-collections4-4.1-javadoc.jar; 赠送源代码:commons-collections4-4.1-sources.jar; 赠送Maven依赖信息文件:commons-collections4-4.1.pom;...
该文件里包含两个.jar包: collections-generic-4.01.jar和looks-2.1.4.jar, 引入collections-generic-4.01.jar: 右击工程--》Build path ——》Add External JAR-->选中collections-generic-4.01.jar --》OK 在源...
一本很好的C#编程教程,适合入门初学者以及相关编程技术人员!
赠送jar包:commons-collections4-4.4.jar; 赠送原API文档:commons-collections4-4.4-javadoc.jar; 赠送源代码:commons-collections4-4.4-sources.jar; 赠送Maven依赖信息文件:commons-collections4-4.4.pom;...
赠送jar包:commons-collections4-4.4.jar; 赠送原API文档:commons-collections4-4.4-javadoc.jar; 赠送源代码:commons-collections4-4.4-sources.jar; 赠送Maven依赖信息文件:commons-collections4-4.4.pom;...
赠送jar包:commons-collections-3.2.2.jar; 赠送原API文档:commons-collections-3.2.2-javadoc.jar; 赠送源代码:commons-collections-3.2.2-sources.jar; 赠送Maven依赖信息文件:commons-collections-3.2.2....
主要介绍了python内置模块collections知识点总结,有兴趣的朋友们学习下。
Collections 中部分方法详解如GridView中Collections.swap
CollectionBuilder-SA CollectionBuilder-SA(“独立”)是用于使用Jekyll创建数字馆藏和展示网站的模板,具体如下: 集合元数据的CSV 图片,PDF,音频或视频文件的文件夹 在您的集合元数据的驱动下,该模板会...
在Java代码运行时报ClassNotDef 缺少包为collcetions4 或者collections15
commons-collections-3.2.1-bin
Arrays Collections Objects Arrays是操作数组对象的工具类 Collections是操作集合对象的工具类 Objects是操作引用数据类型对象的工具类 Arrays的常用方法 普通排序 Arrays.sort(int[] a) Arrays.sort(int[] a, ...
主要介绍了java基础之Collection与Collections和Array与Arrays的区别的相关资料,本文主要说明两者的区别以防大家混淆概念,需要的朋友可以参考下