返回匿名数组java_Java SE学习之数组——匿名数组和不规则数组

本文是学习网络上的文章时的总结以及自己的一点实践。感谢大家无私的分享。

近期偶然遇到了数组的问题,学习了匿名数组和不规则数组。

匿名数组适用于仅仅使用一次的情况;不规则数组适用是每行数据总数不确定的情况。

以下贴上我的小样例

package SE;

import java.util.Random;

/**

*

* Description: 此方法是对匿名数组和不规则数组的学习

*

* @author zhangjunshuai

* @version 1.0

* Create Date: 2014-10-24 下午5:49:22

* Project Name: Java7Thread

*

*

 
 

* Modification History:

* Date Author Version Description

* -----------------------------------------------------------------------------------------------------------

* LastChange: $Date:: $ $Author: $ $Rev: $

*

*

*/

public class Array {

/**

*

*

* @author zhangjunshuai

* @date 2014-10-24 下午5:48:19

* @param args

*/

public static void main(String[] args) {

//1、匿名数组的使用

out1(new String[]{"1","2"});

out2("3","4");

//2、不规则数组的使用

irregular();

}

/*

* 不规则数组

*/

static void irregular(){

int arrays[][];

arrays = new int[3][];

for(int i=0;i

/*Random r = new Random(47);

int h = r.nextInt(13);*/

int h = (int)(Math.random()*16);

arrays[i] = new int[h];

for(int j=0;j

int w = (int)(Math.random()*100);

arrays[i][j] = w;

}

}

//遍历输出

for(int i=0;i

for(int j=0;j

System.out.print(arrays[i][j]+" ");

}

System.out.println();

}

}

static void out1(String[] ss){

for (String string : ss) {

System.out.print(string);

}

System.out.println();

}

static void out2(String... ss){

for (String str : ss) {

System.out.print(str);

}

System.out.println();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值