集合学习--笔记1数组

开始我的第一次博客之旅游:

数组的声明:

int[] a=null; a=new int[3];
声明一个int型的数组a,大小为3

数组的赋值:
方法一:a[0]=7;a[1]=-5;a[2]=10;
方法二:声明的时候就赋值 int[] a=new int[]{7,-5,10};
方法三:int[] a={7,-5,10};

数组的长度:
上面声明的数组长度为3;也可以这样获取:a.length

数组的遍历:
方法一:
<pre name="code" class="html">for(int i=0;i<a.length;i++){
	System.out.println(a[i]);
}
方法二:

 
<pre name="code" class="html">for(int number:a){
     System.out.println(number);
}

二维数组:
 
个人觉得二维数组就是一维数组中包含着多个数组;如 int[][] a=new int[][]{{1,5},{7,4},{-5,12,6}};数组a的长度为3,里面包含着3个小数组。遍历的时候先遍历整体,再
遍历每一个。如:for(int i=0;i<a.length;i++){ int[] b=a[i]; for(int j=0;j<b.length;j++){System.out.println(b[j]);}}将a[0]赋值给数组b,再遍历,将a[1]赋值给数
组b,再遍历。。。

或用增强的for循环
for(int[] num1:a){
    for(int num2:num1){
<span style="white-space:pre">	</span>System.out.print(num2+" ");
<span style="white-space:pre">		</span>}
<span style="white-space:pre">	</span>}


第一次写博客就写这么多。。。表示bu会用csdn<img alt="委屈" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/wronged.gif" />


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值