博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
方法/排序
阅读量:4693 次
发布时间:2019-06-09

本文共 1095 字,大约阅读时间需要 3 分钟。

   int[] arr = new int[]{ 3,6,8,9 };      

System.out.println(arr.length);      

int len = arr . length ;      

System.out.println("数组长度为:" + len);      

/*System.arraycopy方法用于数组复制      

*public static void arraycopy (Object src, int srcPos,Object dest, int destPos, int length)       

src:源数组      srcPos:源数组中的起始位置      dest:目标数组      destPos : 目标数组中的起始位置      length:要复制的数组元素的数量

     int[ ] a = { 10 ,20 ,30 ,40 ,50 };     

     int[ ] a1 = new int[ 6 ] ;     

     System.arraycopy( a , 1 , a1 , 0 , 4 );

结果:20,30,40,50               

排序:          

冒泡排序:                     

  int[] arr = {89,50,84,57,61,20,86};     

for(int i=0;i<arr.length-1;i++){          f

or(int j=0;j<arr.length-1-i;j++){             

if(arr[j]>arr[j+1]){                 

int temp = arr[j];                  arr[j] = arr[j+1];                  arr[j+1] = temp;            

  }  

}  

}               

 Arrays.sort方法用于数组排序:                                 

int[ ] arr = { 49, 81, 1, 64, 77, 50, 0, 54, 77, 18 };        

Arrays.sort( arr ) ;         

 for(int i=0; i<arr.length; i++) {            

System.out.println(arr[i] );      }               

Arrays.copyOf方法用于数组复制:       

   类型[ ]  newArray = Arrays.copyOf ( 类型[ ]  original , int  newLength )               

int [ ] a = { 10,20,30,40,50 } ;          

int [ ] a1 = Arrays . copyOf ( a, 6 );           

数组的“扩容”:            

  int [ ] a = { 10,20,30,40,50 } ;                    

a = Arrays . copyOf ( a, a.length+1 );       

 }

}

转载于:https://www.cnblogs.com/xiaziteng/p/4700553.html

你可能感兴趣的文章
jmeter 取样器--SMTP Sampler
查看>>
你应该知道的Node.js扩展模块——Hashish
查看>>
java 关于集合详解
查看>>
Datetime 使用详解
查看>>
git: fatal: Not a git repository (or any of the parent directories): .git
查看>>
c++ <fstream> 读写文件总结
查看>>
MySQL Replication--半同步复制(Semi-Sync Replication)
查看>>
没事干写写流程审批数据库的设计
查看>>
linux操作系统中安装mysql
查看>>
有用地址
查看>>
class 方法
查看>>
《编程珠玑,字字珠玑》读书笔记完结篇——AVL树
查看>>
VBA trouble
查看>>
HUD Is It A Tree?!!!!!)
查看>>
电梯调度算法(-)
查看>>
Two Sum III - Data Structure Design
查看>>
java web----jsp自定义标签
查看>>
SQL知识
查看>>
krpano之字幕添加
查看>>
面向接口编程 --对象的三种依赖
查看>>