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. 多字节字符集与Unicode字符集

    在计算机中字符通常并不是保存为图像,每个字符都是使用一个编码来表示的,而每个字符究竟使用哪个编码代表,要取决于使用哪个字符集(charset). 多字节字符集: 在最初的时候,Internet上只有一 ...

  2. Carbon document

    <   Getting Started Docs Reference History Contribute Github Introduction The Carbon class is inh ...

  3. JSONObject 的使用学习

    http://www.cnblogs.com/hitwtx/articles/2468633.html put与accumulate,element方法的区别什么? http://blog.csdn. ...

  4. Trapping Rain Water LT42

    The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of ...

  5. Maven构建JavaWeb

    查看java和mvn版本 java -version mvn -v D:\software\yiibai\spring-1.4.3.RELEASE>java -versionjava versi ...

  6. RecyclerView错误

    1. java.lang.NoClassDefFoundError: android.support.v7.widget.RecyclerView 这个错误真TM见鬼,明明jar包里面就有这个类,工程 ...

  7. bootstrap 坑

    1.  表格内存出不来,也不报错 .. 值是对的..  原因是  table  中必须有属性   data-toggle="table" <table id="My ...

  8. hdu 2588(简单的欧拉

    题意:给你一个n,m问你1-n里面(x)有多少对gcd(x, n)>=m. 思路:我们可以设n=a*b, x=a*c,此时我们可以知道b,c是互质的,那么就可以用欧拉来求解 /* gyt Liv ...

  9. 8月的list

    多校的list: 第一周的多校list: k路归并 (思想大概理解了,还没实现 莫比乌斯 树归 第三场的多校list: 斯坦纳树 第四场多校: Pollard_rho算法和Miller_Rabin   ...

  10. IIS Web服务器日志、日志服务器分析

    IIS Web服务器日志.日志服务器分析 EventLog Analyzer是一款全面的工具,用于审计.管理和跟踪您的Microsoft Internet Information Services(I ...