一维数组作为参数:

  • 传数组的引用
  • 创建数组直接传,本质也是传数组的引用
  • 传null
public class Test {

    //数组作为参数时,可以传递3中形式
public void m1(int[] a) {
System.out.println("数组长度是:"+ a.length);
} public static void main(String[] args) {
Test t = new Test(); //创建一个数组,传递数组引用
int[] b = {1,2,3,4,5};
t.m1(b);
//直接创建数组传值
t.m1(new int[]{1,2,3});
//直接传递null,但是次数组不可用
t.m1(null);
}
}

一维数组作为返回值:

  • 返回数组的引用
  • 直接创建一个数组返回,本质上是返回数组的引用
  • 返回null
public class Test {

    //返回数组的引用
public String[] m1() {
String[] s = {"abc","de"};
return s;
} //返回直接创建的数组
public String[] m2() {
return new String[]{"a", "b","c"};
} //返回null
public String[] m3() {
return null;
} public static void main(String[] args) {
Test t = new Test(); String[] s1 = t.m1();
System.out.println("接收到的数组长度:" + s1.length);
String[] s2 = t.m2();
System.out.println("接收到的数组长度:" + s2.length);
String[] s3 = t.m3();
System.out.println("接收到的数组长度:" + s3.length);
}
}

最新文章

  1. Java关于Properties用法的总结(一)
  2. centos7 hostname
  3. dispay属性的block,inline,inline-block
  4. 为什么Web 设计会‘死’?
  5. Qt之QSizePolicy
  6. Oracle 中的 TO_DATE 和 TO_CHAR 函数
  7. online ddl 跟踪
  8. C# to Maxscript
  9. C# this关键字详解
  10. 【C语言】printf函数详解
  11. Missing Ranges 解答
  12. 一个action读取另一个action里的session
  13. 【R】正态检验与R语言
  14. ASP.NET Core 2.1对GDPR的支持
  15. es6那些事儿
  16. Jmeter也能IP欺骗!
  17. windows(xshell)免密码登录
  18. sitecore系统教程之Item快速了解
  19. Luogu P1558 色板游戏
  20. python变量名感悟

热门文章

  1. ping 127.0.0.1和ping本地ip分别测试什么?
  2. (16)Python练习题
  3. swift的调用约定
  4. 在linux系统下安装配置apacheserver
  5. 统计单词数 OpenJ_Bailian - 4030(字符串处理)
  6. css3属性中background-clip与background-origin的用法释疑
  7. go标准库的学习-crypto/sha1
  8. 让sublime text3支持Vue语法高亮显示
  9. 【Codeforces 1132F】Clear the String
  10. 利用git向github上远程提交一个自己的开源项目