- 1、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
4.3_数组的引用传递
JAVA 应用开发详解
第4章:数组与方法
—— 数组的引用传递
APP开发工作室
2015年8月
本章目标
掌握数组的引用传递
可以使用方法接收或返回一个数组
了 Java对数组操作的支持
传递及返回数组
之前的方法操作传递和返回的都是基本数据类型,但是方法中也可用
来传递和返回数组。如果要向方法中传递一个数组,则方法的接收参
数处必须是符合其类型的数组。而且数组属于引用数据类型,所以在
把数组传递进方法之后,如果方法对数组本身做了任何修改,修改结
果都是会保存下来的。
向方法中传递数组
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; 修改第一个元素的内容
}
}
内存状态
使用方法返回一个数组
既然方法可以接收一个数组,那么方法也就可以返回一个
数组,则此时,只需要在返回值类型声明处明确的写出返
回的数组类型即可
public class ArrayRefDemo02 {
public static void main(String[] args) {
int temp[] = fun(); 通过方法实例化数组
print(temp); 向print()方法中传递数组
}
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; 返回数组
}
}
范例:数组排序
public class Ar
您可能关注的文档
- analysis to establish a socialist core value system and building a harmonious campus(分析建立社会主义核心价值体系,建设和谐校园).doc
- analysis to build formative assessment model for college english teaching(分析构建大学英语教学形成性评价模型).doc
- analysis to establish the budget audit assessment of the degree of implementation mechanisms(分析建立预算审计评估的程度的实现机制).doc
- analysis to strengthen the moral education of students in junior high school it teaching(分析来加强学生的道德教育在初中教学).doc
- analysis to strengthen the teaching building improve the quality of education(分析来加强教学建设提高教育质量).doc
- analysis to teach science language learning ability of students(分析科学教的学生语言学习能力).doc
- analysis trial detention period defined in the context of the new code of criminal procedure(分析试验停留期的上下文中定义的刑事诉讼程序的新代码).doc
- analysis under the new curriculum changes in mathematics teaching(分析新课程下数学教学的变化).doc
- analysis using a new instrument analysis of pine fiber morphology analysis of ctmp pulp fiber morphology(使用新的分析仪器分析松纤维形态分析ctmp纸浆纤维形态).doc
- analysis vendors legitimacy(分析供应商的合法性).doc
文档评论(0)