1.

public class ArrayRefDemo01{
public static void main(String args[]){
int temp[] = {1,3,5} ; // 利用静态初始化方式定义数组
fun(temp) ; // 传递数组
for(int i=0;i<temp.length;i++){
System.out.print(temp[i] + "、") ;
}
}
public static void fun(int x[]){ // 接收整型数组的引用
x[0] = 6 ; // 修改第一个元素
}
};

运行结果:

6、3、5、

2.

public class ArrayRefDemo02{
public static void main(String args[]){
int temp[] = fun() ; // 通过方法实例化数组
print(temp) ; // 打印数组内容
}
public static void print(int x[]){
for(int i=0;i<x.length;i++){
System.out.print(x[i] + "、") ;
}
}
public static int[] fun(){ // 返回一个数组
int ss[] = {1,3,5,7,9} ; // 定义一个数组
return ss ;
}
};

运行结果:

1,3,5,7,9

3.

public class ArrayRefDemo03{
public static void main(String args[]){
int score[] = {67,89,87,69,90,100,75,90} ; // 定义整型数组
int age[] = {31,30,18,17,8,9,1,39} ; // 定义整型数组
sort(score) ; // 数组排序
print(score) ; // 数组打印
System.out.println("\n---------------------------") ;
sort(age) ; // 数组排序
print(age) ; // 数组打印
}
public static void sort(int temp[]){ // 执行排序操作
for(int i=1;i<temp.length;i++){
for(int j=0;j<temp.length;j++){
if(temp[i]<temp[j]){
int x = temp[i] ;
temp[i] = temp[j] ;
temp[j] = x ;
}
}
}
}
public static void print(int temp[]){ // 输出数组内容
for(int i=0;i<temp.length;i++){
System.out.print(temp[i] + "\t") ;
}
}
};

运行结果:

67 69 75 87 89 90 90 100
---------------------------
1 8 9 17 18 30 31 39

4.

public class ArrayRefDemo04{
public static void main(String args[]){
int score[] = {67,89,87,69,90,100,75,90} ; // 定义整型数组
int age[] = {31,30,18,17,8,9,1,39} ; // 定义整型数组
java.util.Arrays.sort(score) ; // 数组排序
print(score) ; // 数组打印
System.out.println("\n---------------------------") ;
java.util.Arrays.sort(age) ; // 数组排序
print(age) ; // 数组打印
}
public static void print(int temp[]){ // 输出数组内容
for(int i=0;i<temp.length;i++){
System.out.print(temp[i] + "\t") ;
}
}
};

运行结果:

67 69 75 87 89 90 90 100
---------------------------
1 8 9 17 18 30 31 39

5.

public class ArrayRefDemo05{
public static void main(String args[]){
int i1[] = {1,2,3,4,5,6,7,8,9} ; // 源数组
int i2[] = {11,22,33,44,55,66,77,88,99} ;// 目标数组
copy(i1,3,i2,1,3) ; // 调用拷贝方法
print(i2) ;
}
// 源数组名称,源数组开始点,目标数组名称,目标数组开始点,拷贝长度
public static void copy(int s[],int s1,int o[],int s2,int len){
for(int i=0;i<len;i++){
o[s2+i] = s[s1+i] ; // 进行拷贝操作
}
}
public static void print(int temp[]){ // 输出数组内容
for(int i=0;i<temp.length;i++){
System.out.print(temp[i] + "\t") ;
}
}
};

运行结果:

11 4 5 6 55 66 77 88 99

6.

public class ArrayRefDemo06{
public static void main(String args[]){
int i1[] = {1,2,3,4,5,6,7,8,9} ; // 源数组
int i2[] = {11,22,33,44,55,66,77,88,99} ;// 目标数组
System.arraycopy(i1,3,i2,1,3) ; // 调用Java中对数组支持的拷贝方法
print(i2) ;
}
public static void print(int temp[]){ // 输出数组内容
for(int i=0;i<temp.length;i++){
System.out.print(temp[i] + "\t") ;
}
}
};

运行结果:

11 4 5 6 55 66 77 88 99

Java学习---- 数组的引用传递的更多相关文章

  1. java对象Integer不能引用传递

    java对象Integer不能引用传递 /** * The value of the <code>Integer</code>. * * @serial */ private ...

  2. Java中参数的引用传递和值传递

    1.一些定义 值传递:把实际传入参数的值,在内存中赋值一份 引用传递:传入的是实际参数的地址 2.传递基本类型的参数 因为Java是值传递,那就不难理解下面的代码不交换任何值 swap(Type ar ...

  3. Java 从数组来看值传递和引用传递

    从数组来看值传递和引用传递 惯例先看一段代码 public class DemoCollection14 { public static void main(String[] args) { Stri ...

  4. 078、Java数组之数组的引用传递

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  5. Java学习之一(引用相关)

    1.Java概述 首先,Java是一门面向对象的编程语言.相对于C/C++等语言,Java中没有指针,但是这不代表指针等知识不重要:Java中不存在多继承但是存在多接口.在我自己的学习过程之中,我偏向 ...

  6. java传值和通过引用传递

    第一次使用int实验: public class TTEST { private static List<UserEntity> mList = new LinkedList<Use ...

  7. Java基础_0310:引用传递

    引用传递 引用传递是Java之中最让初学者费解的概念,而在实际的开发之中,引用传递又有着非常重要的作用: 引用传递的核心在于同一块堆内存空间被不同的栈内存所指向: 范例:第一道引用传递范例 class ...

  8. java子类数组的引用转换成超类数组的引用

    public class Person { } public class Student extends Person{ private String name; public Student(Str ...

  9. Java学习——数组的基础知识

    数组的特点.分类:一维.二维数组的使用:数组的声明和初始化.调用数组的指定位置的元素.获取数组的长度.遍历数组.数组元素的默认初始化值

随机推荐

  1. NC 5的开发环境起不了客户端

    5的开发环境,中间件启动无异常,但是在起客户端时报错,连中间件也关闭了. 添加图中两个jdk下的包

  2. NC 6系后台调用接口保存单据

    IPFBusiAction ipf = (IPFBusiAction)NCLocator.getInstance().lookup(IPFBusiAction.class); ipf.processA ...

  3. UI设计教程:关于版式设计

    版式设计是视觉传达的重要手段之一,版式设计,即把有限的视觉元素在版面页进行有效的视觉组合,最优化地传达信息的同时,去影响受众,使受众产生视觉上的美感. 版式设计基本流程  在进行版式设计时,设计作品的 ...

  4. clean

    启动tomcat 报 Could not delete D:/online/.metadata/.plugins/org.eclipse.wst.server.core/tm  

  5. 如何使用putty远程连接linux

    如何使用putty远程连接linux | 浏览:5001 | 更新:2013-08-24 10:36 1 2 3 4 5 分步阅读 putty是一款超轻量级的运行在windows操作系统上的用于远程连 ...

  6. spring学习 三 框架的搭建

    1 导入jar包 spring启来最少要5个包,四个核心包和一个依赖的日志包 2 创建配置文件 在dynamic web project下的src目录下,创建一个spring的xml配置文件,名称可以 ...

  7. Android Makefile中是 如何识别 TARGET_PRODUCT 的

    http://blog.csdn.net/stevenliyong/article/details/5285334 今天有时间小看一下Android 的Makefile, 终于稍有明白Android ...

  8. Java第3章笔记

    if基本语法: if(条件){// 表达式   // 代码块   } eg:    int a = 10;    if(a > 1){  System.out.println("内容& ...

  9. day10作业—(闭包迭代器递归)

    补充:一个星号的  打散和聚合 a, b , *c = [1,2, 1,4] print( a , b , *c) #1 2 1 4 print(a, b, c) #1 2 [1, 4] *c , = ...

  10. git 如何更改某个提交内容/如何把当前改动追加到某次commit上? git rebase

    原文地址        http://www.jianshu.com/p/8d666830e826 [自己总结] 0, git diff git diff a b 是以a为基准,把b和a的区别展示出来 ...