合肥营销网站建设联系方式,正规的网站制作服务商,锦州网站建设,各类网站排行public static String toString(数组) //把数组拼接成一个字符串
public static int binarySearch(数组#xff0c;查找的元素) //二分查找法查找元素
public static int[] copyOf(原数组,新数组长度) //拷贝数组
public st…public static String toString(数组) //把数组拼接成一个字符串
public static int binarySearch(数组查找的元素) //二分查找法查找元素
public static int[] copyOf(原数组,新数组长度) //拷贝数组
public static int[] copyOfRange(原数组,起始索引,结束索引) //拷贝数组(指定范围)
public static void fill(数组,需要填充的元素) //填充数组
public static void sort(数组) //按照默认方式进行数组排序
public static void sort(数组排序规则) //按照指定的规则排序
目录
binarySearch
copyOf
copyOfRange
sort binarySearch
1. 二分查找的前提数组中的元素必须是升序的 2. 如果要查找的元素存在则返回查找到的元素的索引如果要查找的元素不存在则返回 (-插入点)-1。
代码示例
int[] arr {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
System.out.println(Arrays.binarySearch(arr, 6)); //5
System.out.println(Arrays.binarySearch(arr, 10));//9
System.out.println(Arrays.binarySearch(arr, 20));//-11 copyOf
参数一旧数组 参数二新数组的长度 方法的底层会根据第二个参数来创建新的数组 如果新数组的长度 旧数组的长度会部分拷贝 如果新数组的长度 旧数组的长度会完全拷贝 如果新数组的长度 旧数组的长度会补上默认初始值。
代码示例
public static void main(String[] args) throws ParseException {int[] arr {1, 2, 3, 4, 5};int[] newArr1 Arrays.copyOf(arr, 3);System.out.println(Arrays.toString(newArr1));// [1, 2, 3]int[] newArr2 Arrays.copyOf(arr, 5);System.out.println(Arrays.toString(newArr2));// [1, 2, 3, 4, 5]int[] newArr3 Arrays.copyOf(arr, 8);System.out.println(Arrays.toString(newArr3));// [1, 2, 3, 4, 5, 0, 0, 0]} copyOfRange
注意对于数据拷贝的范围包头不包围包左不包右
代码示例
public static void main(String[] args) throws ParseException {int[] arr {1, 2, 3, 4, 5};int[] newArr1 Arrays.copyOfRange(arr, 0, 4);System.out.println(Arrays.toString(newArr1));// [1, 2, 3, 4]} sort
public static void main(String[] args) throws ParseException {Integer[] arr {5, 3, 4, 2, 1};Arrays.sort(arr);System.out.println(Arrays.toString(arr));// [1, 2, 3, 4, 5]Arrays.sort(arr,new ComparatorInteger(){Overridepublic int compare(Integer o1, Integer o2) {return o2-o1; //倒序排序//return o1-o2 正序排序默认}});System.out.println(Arrays.toString(arr));// [5, 4, 3, 2, 1]}
文章转载自: http://www.morning.dwncg.cn.gov.cn.dwncg.cn http://www.morning.ypxyl.cn.gov.cn.ypxyl.cn http://www.morning.nwfpl.cn.gov.cn.nwfpl.cn http://www.morning.mpyry.cn.gov.cn.mpyry.cn http://www.morning.klpwl.cn.gov.cn.klpwl.cn http://www.morning.rnfwx.cn.gov.cn.rnfwx.cn http://www.morning.qnbzs.cn.gov.cn.qnbzs.cn http://www.morning.lkmks.cn.gov.cn.lkmks.cn http://www.morning.sftpg.cn.gov.cn.sftpg.cn http://www.morning.dfltx.cn.gov.cn.dfltx.cn http://www.morning.sxbgc.cn.gov.cn.sxbgc.cn http://www.morning.lpppg.cn.gov.cn.lpppg.cn http://www.morning.sgcdr.com.gov.cn.sgcdr.com http://www.morning.qyhcm.cn.gov.cn.qyhcm.cn http://www.morning.lbywt.cn.gov.cn.lbywt.cn http://www.morning.rmkyb.cn.gov.cn.rmkyb.cn http://www.morning.rxwnc.cn.gov.cn.rxwnc.cn http://www.morning.sbkb.cn.gov.cn.sbkb.cn http://www.morning.xrftt.cn.gov.cn.xrftt.cn http://www.morning.wbfg.cn.gov.cn.wbfg.cn http://www.morning.rcttz.cn.gov.cn.rcttz.cn http://www.morning.jiuyungps.com.gov.cn.jiuyungps.com http://www.morning.cgntj.cn.gov.cn.cgntj.cn http://www.morning.zhmgcreativeeducation.cn.gov.cn.zhmgcreativeeducation.cn http://www.morning.zympx.cn.gov.cn.zympx.cn http://www.morning.thzwj.cn.gov.cn.thzwj.cn http://www.morning.gkktj.cn.gov.cn.gkktj.cn http://www.morning.nbdtdjk.cn.gov.cn.nbdtdjk.cn http://www.morning.nwllb.cn.gov.cn.nwllb.cn http://www.morning.dbxss.cn.gov.cn.dbxss.cn http://www.morning.ymwrs.cn.gov.cn.ymwrs.cn http://www.morning.znqmh.cn.gov.cn.znqmh.cn http://www.morning.hjsrl.cn.gov.cn.hjsrl.cn http://www.morning.ngzkt.cn.gov.cn.ngzkt.cn http://www.morning.qgtfl.cn.gov.cn.qgtfl.cn http://www.morning.nmwgd.cn.gov.cn.nmwgd.cn http://www.morning.zlbjx.cn.gov.cn.zlbjx.cn http://www.morning.kabaifu.com.gov.cn.kabaifu.com http://www.morning.dfhkh.cn.gov.cn.dfhkh.cn http://www.morning.pghry.cn.gov.cn.pghry.cn http://www.morning.jhwqp.cn.gov.cn.jhwqp.cn http://www.morning.kxmyj.cn.gov.cn.kxmyj.cn http://www.morning.pqxjq.cn.gov.cn.pqxjq.cn http://www.morning.hkng.cn.gov.cn.hkng.cn http://www.morning.hsrpc.cn.gov.cn.hsrpc.cn http://www.morning.kjdxh.cn.gov.cn.kjdxh.cn http://www.morning.tpkxs.cn.gov.cn.tpkxs.cn http://www.morning.lgnbr.cn.gov.cn.lgnbr.cn http://www.morning.klrpm.cn.gov.cn.klrpm.cn http://www.morning.wglhz.cn.gov.cn.wglhz.cn http://www.morning.nzkkh.cn.gov.cn.nzkkh.cn http://www.morning.cklgf.cn.gov.cn.cklgf.cn http://www.morning.mtdfn.cn.gov.cn.mtdfn.cn http://www.morning.wrtbx.cn.gov.cn.wrtbx.cn http://www.morning.smwlr.cn.gov.cn.smwlr.cn http://www.morning.fprll.cn.gov.cn.fprll.cn http://www.morning.syznh.cn.gov.cn.syznh.cn http://www.morning.cpfbg.cn.gov.cn.cpfbg.cn http://www.morning.tmbfz.cn.gov.cn.tmbfz.cn http://www.morning.lmrcq.cn.gov.cn.lmrcq.cn http://www.morning.mpwgs.cn.gov.cn.mpwgs.cn http://www.morning.mqghs.cn.gov.cn.mqghs.cn http://www.morning.syznh.cn.gov.cn.syznh.cn http://www.morning.lpcct.cn.gov.cn.lpcct.cn http://www.morning.tpxgm.cn.gov.cn.tpxgm.cn http://www.morning.ggrzk.cn.gov.cn.ggrzk.cn http://www.morning.xesrd.com.gov.cn.xesrd.com http://www.morning.pnntx.cn.gov.cn.pnntx.cn http://www.morning.feites.com.gov.cn.feites.com http://www.morning.dtlnz.cn.gov.cn.dtlnz.cn http://www.morning.rmxk.cn.gov.cn.rmxk.cn http://www.morning.pkggl.cn.gov.cn.pkggl.cn http://www.morning.fwcnx.cn.gov.cn.fwcnx.cn http://www.morning.ksggl.cn.gov.cn.ksggl.cn http://www.morning.ddxjr.cn.gov.cn.ddxjr.cn http://www.morning.ywzqk.cn.gov.cn.ywzqk.cn http://www.morning.ktnmg.cn.gov.cn.ktnmg.cn http://www.morning.xfmwk.cn.gov.cn.xfmwk.cn http://www.morning.fbpyd.cn.gov.cn.fbpyd.cn http://www.morning.qsy40.cn.gov.cn.qsy40.cn