package study.stage2;

import java.util.Arrays;

/**
* Created by Sandy.Liu on 2017/7/19.
*/
public class ArrayTest {
public static void main(String[] args) throws Exception{
int array[] = {3,4,2,24,6,-23,-4,-56};
System.out.println(array.length);//8
printArray(array);//{3,4,2,24,6,-23,-4,-56}
array = insertElement(array,1,5);
printArray(array);//{3,4,2,24,6,1,-23,-4,-56}
Arrays.sort(array);
printArray(array);//{-56,-23,-4,1,2,3,4,6,24}
int index = Arrays.binarySearch(array,4);
System.out.println(index);
}
public static void printArray(int array[]){
for(int i=0;i<array.length;i++){
System.out.print(array[i]+" ");
}
System.out.println();
} public static int[] insertElement(int original[], int element, int index){
int length = original.length;
if(index<0){
System.out.println("out of range");
}
else if(index>original.length){
System.out.println("out of range");
}
int destination[] = new int[length+1];
//arrayCopy(originalArray,index, targetArray,index1,count) 把orginal里的从index位开始的值copy到targetArray里从index1开始的位置,
// ,copy的位数是count
System.arraycopy(original,0,destination,0,index);
destination[index]=element;
System.arraycopy(original,index,destination,index+1,length-index);
return destination; }
}

java System.arraycopy()的更多相关文章

  1. java System.arrayCopy使用说明

    java System.arrayCopy使用说明 java.lang.System.arraycopy() 方法复制指定的源数组的数组,在指定的位置开始,到目标数组的指定位置. 下面是 System ...

  2. JAVA System.arraycopy 和Arrays.copyof 效率比较

    System.arraycopy()源码.可以看到是native方法: native关键字说明其修饰的方法是一个原生态方法,方法对应的实现不是在当前文件,而是在用其他语言(如C和C++)实现的文件中. ...

  3. java System.arraycopy 数组复制和合并

    public class Test { public static void main(String[] args) { Integer[] a = {1,2,3}; Integer[] b = {4 ...

  4. [Java] System.arraycopy 数组复制

    函数原型: public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length) ; s ...

  5. Exception raised during rendering: java.lang.System.arraycopy([CI[CII)V

    最近下载一个新版本的adt-bundle,Android API是20. 把Plain Text控件往布局上面拖时,发现拖不上去,出现了下面的错误: Exception raised during r ...

  6. java的system.arraycopy()方法

    java.lang.System的静态方法arraycopy()可以实现数组的复制,讲课的老师说这个方法效率比较高,如果数组有成千上万个元素,那么用这个方法,比用for语句循环快不少.于是我试了试,发 ...

  7. [Java基础] System.arraycopy使用

    转载自:http://blog.csdn.net/java2000_net/article/details/4059465 System提供了一个native 静态方法arraycopy(),我们可以 ...

  8. ECLIPSE android 布局页面文件出错故障排除Exception raised during rendering: java.lang.System.arraycopy([CI[CII)V

    在布局添加控件手动添加还是拖的添加,添加edittext后布局就不好用,其他控件好用,然后就说下面这段话 Exception raised during rendering: java.lang.Sy ...

  9. java数组的拷贝四种方法:for、clone、System.arraycopy、arrays.copyof

    public class ArrayCopy{ public static void main(String []args){ int []a = {1,3,4,5}; toPrint(a); int ...

随机推荐

  1. DevExpress WPF v18.2新版亮点(四)

    行业领先的.NET界面控件2018年第二次重大更新——DevExpress v18.2日前正式发布,本站将以连载的形式为大家介绍新版本新功能.本文将介绍了DevExpress WPF v18.2的新功 ...

  2. matlab中的reshape快速理解,卷积和乘积之间的转换

    reshape: THe convertion between convolution and multiplication:

  3. sptring boot 修改默认Banner

    一.自定义banner 启动Spring Boot项目时,在控制台或日志中会默认显示一个Banner,如图所示: 在我们的项目中更希望使用自己的Banner,这样看起来更帅写,但是这对于程序员来说并不 ...

  4. 玩转 React【第02期】:恋上 React 模板 JSX

    往期回顾 前文中我们讲解了利用 ReactElement 来编写React程序,但是我们也看到这种方式编写 React 特别的麻烦,而且层级结构特别不清晰.今天我们来看一种优雅的编写React的代码的 ...

  5. [转]JavaScript与元素间的抛物线轨迹运动

    在张鑫旭的博客看到这个抛物线的小动画,觉得很感兴趣,转载一下方便研究~ 原文地址:http://www.zhangxinxu.com/wordpress/?p=3855 在页面上添加元素的位移动画,除 ...

  6. Eclipse_设置_01_自动提示

  7. 前端笔记 (3.JavaScript 1)

    JavaScript 是属于网络的脚本语言! JavaScript 是一种轻量级的编程语言. JavaScript 是可插入 HTML 页面的编程代码. JavaScript 插入 HTML 页面后, ...

  8. 河南省第四届ACM省赛(T3) 表达式求值

    表达式求值 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Dr.Kong设计的机器人卡多掌握了加减法运算以后,最近又学会了一些简单的函数求值,比如,它知道函数min ...

  9. Python学习笔记第八周

    目录: 一.基础概念 1.动态导入模块 2.断言机制 3.SocketServer 二.作业 FTP服务器 三.单独注明 1.类中装饰器 2.进度条 一.基础概念 1.动态导入模块 有时在编程过程中, ...

  10. C高级第三次作业

    C高级第三次作业(1) 6-1 输出月份英文名 1.设计思路 (1)算法: 第一步:定义整型变量n,字符指针s,输入一个数赋给n. 第二步:调用函数getmonth将值赋给s. 第三步:在函数getm ...