day09

数组

  1. 数组硕果仅存的优点就是效率.
  2. 新生成一个数组对象时,其中所有的引用被自动初始化为null,所以检查其中的引用是否为null,即可知道数组的某个位置是否存有对象.同样基本类型的数组如果是数值型的,就被自动初始化为0,如果时字符型(char)的,就被自动初始化为(char)0;如果是布尔值(boolean),就被自动初始化为false.
  3. Arrays.deepToString()方法,它可以将多维素组转换为多个String.它对基本类型数组和对象数组都起作用.
  4. System.arraycopy()
  • public static void arraycopy(Object src,int srcPos,Object dest,int destPos,int length)

Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination array. A subsequence of array components are copied from the source array referenced by src to the destination array referenced by dest. The number of components copied is equal to the length argument. The components at positions srcPos through srcPos+length-1 in the source array are copied into positions destPos through destPos+length-1, respectively, of the destination array.
Parameters:
src - the source array.
srcPos - starting position in the source array.
dest - the destination array.
destPos - starting position in the destination data.
length - the number of array elements to be copied.

动态初始化:

  • 数据类型[] 数组名 = new 数据类型[长度];
  • 数据类型:--->决定了数组能够存放什么样的数据
  • [] :---->代表是一个数组
  • 数组名 :--->为数组起的名字,为了找到数组
  • new:---> 向堆内存申请空间的关键字
  • 长度: --->数组中能够存放多少个数据
  • 特点: 我们程序员给定长度,由系统给定默认值!!!

静态初始化:

完整的格式: 数据类型[] 数组名 = new 数据类型[不能写长度!!!!]{元素1,元素2...};
省略的格式:
数据类型[] 数组名 = {元素1,元素2...};
内存划分
*栈
1. 存放局部变量 ----> 定义在方法里面,或者方法声明上(参数列表)的变量都是局部变量
2. 所有的方法都在栈里面运行
3. 堆:
4. 作用:存放new出来的东西
5. 特点:1.都有地址值2.都有默认值整数: 0 小数:0.0 字符:'\u0000 布尔:false 引用数据类型:null

方法区

  • 存放字节码对象.class相关的信息
  • 存放静态相关的东西static
  • 本地方法栈 ---->系统相同
  • 寄存器 --->cpu

获取数组的长度
格式:数组名.length

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 叶落归根飘飞舞 四季沐歌冬日藏, 黎明曙光冬季临, 春来绿芽树梢挂!
    A把时间当做朋友阅读 962评论 1 1
  • 不知道为什么这几天心情不好! 有一天,这个女孩在路上碰见一个男孩,这个女孩很痴迷的注视着这个男孩子。女孩听...
    陪你越星空阅读 1,540评论 0 1
  • 尚俊平,焦点网络中级,坚持分享822天,2018年7月24日,星期二 没有期待,静待花开。看了朱金凤老师的《语言的...
    32598db751bb阅读 884评论 0 0
  • 艳阳轻抚花渐开,窗里朝暮仍清寒。 猫犬思春吠终日,燕子不语忆旧年。
    天地过客的笔记阅读 1,196评论 0 0