Arrays 001
1.1 Array Initalization
First of all, we need know Java arrays is static. When the array is initialized, the length of the array is immutable. The expansion of the arraylist is to create a larger array, and then copy the original array to the new array and add new elements. Java arrays must be initialzed before they can be used. Initialization is to allocate memory space for array objects.If we use arraylist but no explicit array length definition. The default length of the array is 10.
And Java array variables are reference variables. Using static initialization does not need to specify the length of the array, the system determines the length of the array. When performing dynamic array initialization, the system assigns default values to each array element.
The array element type is an integer type in the basic type(byte, short, int, long), and the default value is 0.
The array element type is a floating-point type in the base type(float, double), with a default value of 0.0.
The array element type is a character type in the basic type(char), and the default value is \u0000.
The array element type is a boolean type in the basic type, and the default value is false.
The array element type is a reference type in the basic type, and the default value is null.
Do not specify both the length of the array and the initial value of each array element when initializing the array.
summary: Java arrays are static. Once the initialization of the array is complete, the space allocation of the array elements is ended. The program can only change the value of the array elements, and cannot modify the length of the array.
An array variable in Java is a reference variable. And array variable is not an array, it just points to an array object in heap memory. Therefore changing the array referenced by an array variable will cause the illusion of variable array length.
Initialization of basic data types, the values of array elements are stored directly in the corresponding array elements. The program directly allocates memory space for the array, and then stores the values of the array elements into the corresponding memory.
All local variables are stored in the stack memory. Whether it is a basic data type variable or a reference type variable, it is stored in its own method stack area. Howerver, the objects referenced by reference type variables are always stored in heap memory. Object in heap memory can only be accessed through reference variable. A reference variable is essentially a pointer. As long as the program accesses the property or calls a method through the reference variable, the reference variable will be replaced by the object which it references.
Because of the nature of data in heap memory, array objects in heap memory require array reference variable to access. Avoid direct access to the data in the heap memory in the Java language can ensure that the program is more rebust. The program cannot directly access and modify the data in the heap memory, which protects the integrity of the data in the memory.
Arrays 001的更多相关文章
- AtCoder Petrozavodsk Contest 001 B - Two Arrays
Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement You are given two inte ...
- AtCoder Grand Contest 001 D - Arrays and Palindrome
题目传送门:https://agc001.contest.atcoder.jp/tasks/agc001_d 题目大意: 现要求你构造两个序列\(a,b\),满足: \(a\)序列中数字总和为\(N\ ...
- Atcoder Grand Contest 001 D - Arrays and Palindrome(构造)
Atcoder 题面传送门 洛谷题面传送门 又是道思维题,又是道把我搞自闭的题. 首先考虑对于固定的 \(a_1,a_2,\dots,a_n;b_1,b_2,\dots,b_m\) 怎样判定是否合法, ...
- 经常使用的系统类Math、Arrays、System、BigInteger和BigDecimal以及日期类,时间戳
一.Math 常用类: //看看Math常用的方法(静态方法)//1.abs绝对值int abs = Math . abs(-9);System. out . printLn(abs);//9//2. ...
- Java程序员的日常—— Arrays工具类的使用
这个类在日常的开发中,还是非常常用的.今天就总结一下Arrays工具类的常用方法.最常用的就是asList,sort,toStream,equals,copyOf了.另外可以深入学习下Arrays的排 ...
- 使用 Arrays 类操作 Java 中的数组
Arrays 类是 Java 中提供的一个工具类,在 java.util 包中.该类中包含了一些方法用来直接操作数组,比如可直接实现数组的排序.搜索等(关于类和方法的相关内容在后面的章节中会详细讲解滴 ...
- 【转】java.util.Arrays.asList 的用法
DK 1.4对java.util.Arrays.asList的定义,函数参数是Object[].所以,在1.4中asList()并不支持基本类型的数组作参数. JDK 1.5中,java.util.A ...
- System.arraycopy()和Arrays.copyOf()的区别
先看看System.arraycopy()的声明: public static native void arraycopy(Object src,int srcPos, Object dest, in ...
- 计算机程序的思维逻辑 (31) - 剖析Arrays
数组是存储多个同类型元素的基本数据结构,数组中的元素在内存连续存放,可以通过数组下标直接定位任意元素,相比我们在后续章节介绍的其他容器,效率非常高. 数组操作是计算机程序中的常见基本操作,Java中有 ...
随机推荐
- uvloop官网翻译
魔术堆栈 uvloop:快速的Python网络连接 作者Yury Selivanov @ 1st1 2016年5月3日 TL; DR asyncio是Python标准库附带的异步I / O框架.在此博 ...
- python-装饰器初识,闭包
函数名的运⽤, 第⼀类对象 ⼀. 函数名的运⽤. 函数名是⼀个变量, 但它是⼀个特殊的变量, 与括号配合可以执⾏函数的变量 1. 函数名的内存地址 def func(): print("呵呵 ...
- 结对编程(四则运算题目生成器core第七组)对接心得
在这篇博客博主想记录一下此次结队编程作业中与ui组对接的心得.在这里我也想表达一下对涂涵越同学的敬佩,他遇到困难时孜孜不倦求解的毅力着实让我佩服,我们在dll的生成上遇到了很大的困难,要不是他的坚持我 ...
- PHP中unset和null的比较
起因 因为感兴趣于unset($var)和$var=null的区别,于是找了一个stackoverflow高分问题及答案,翻译以供参考. 注:以下的问题和答案翻译自http://stackoverfl ...
- ASE——热身作业自我介绍
自我介绍 大家好我是王皓,由于之前忙于保研的机试和面试导致第一次作业就拖到第二次写blog的时候才交(非常抱歉..)我喜欢玩CTF,觉得学习安全方向的知识,寻找软件或者硬件的漏洞是一件非常有意义且有趣 ...
- Educational Codeforces Round 60 (Rated for Div. 2) E. Decypher the String
题目大意:这是一道交互题.给你一个长度为n的字符串,这个字符串是经过规则变换的,题目不告诉你变换规则,但是允许你提问3次:每次提问你给出一个长度为n的字符串,程序会返回按变换规则变换后的字符串,提问3 ...
- HIVE了解及SQL基础命令
hive(数据仓库工具) Hive是一个数据仓库基础工具在Hadoop中用来处理结构化数据.它架构在Hadoop之上,总归为大数据,并使得查询和分析方便.并提供简单的sql查询功能,可以将sql语句转 ...
- 【Java学习笔记】Java的垃圾回收机制
搬以前写的博客[2014-12-30 15:07] 以前很少关注内存的问题,基本没有关注,这方面的小白,原因在于自己都是写的自我娱乐的小程序,不关注性能,不是提供服务.而企业级别的应用在程序稳健性方面 ...
- vue 使用Better-Scroll
注意点 1. 外层容器wrapper要设置高度,并且overflow:hidden. 2. wrapper里面的需要一个div包裹所有内容 3. 样式成功 4. 以上就是可以滚动的情况,wrappe ...
- java des 加密/解密
JAVA实现 加密 注意:DES加密和解密过程中,密钥长度都必须是8的倍数 public byte[] desCrypto(byte[] datasource, String password) { ...