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的更多相关文章

  1. AtCoder Petrozavodsk Contest 001 B - Two Arrays

    Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement You are given two inte ...

  2. AtCoder Grand Contest 001 D - Arrays and Palindrome

    题目传送门:https://agc001.contest.atcoder.jp/tasks/agc001_d 题目大意: 现要求你构造两个序列\(a,b\),满足: \(a\)序列中数字总和为\(N\ ...

  3. Atcoder Grand Contest 001 D - Arrays and Palindrome(构造)

    Atcoder 题面传送门 洛谷题面传送门 又是道思维题,又是道把我搞自闭的题. 首先考虑对于固定的 \(a_1,a_2,\dots,a_n;b_1,b_2,\dots,b_m\) 怎样判定是否合法, ...

  4. 经常使用的系统类Math、Arrays、System、BigInteger和BigDecimal以及日期类,时间戳

    一.Math 常用类: //看看Math常用的方法(静态方法)//1.abs绝对值int abs = Math . abs(-9);System. out . printLn(abs);//9//2. ...

  5. Java程序员的日常—— Arrays工具类的使用

    这个类在日常的开发中,还是非常常用的.今天就总结一下Arrays工具类的常用方法.最常用的就是asList,sort,toStream,equals,copyOf了.另外可以深入学习下Arrays的排 ...

  6. 使用 Arrays 类操作 Java 中的数组

    Arrays 类是 Java 中提供的一个工具类,在 java.util 包中.该类中包含了一些方法用来直接操作数组,比如可直接实现数组的排序.搜索等(关于类和方法的相关内容在后面的章节中会详细讲解滴 ...

  7. 【转】java.util.Arrays.asList 的用法

    DK 1.4对java.util.Arrays.asList的定义,函数参数是Object[].所以,在1.4中asList()并不支持基本类型的数组作参数. JDK 1.5中,java.util.A ...

  8. System.arraycopy()和Arrays.copyOf()的区别

    先看看System.arraycopy()的声明: public static native void arraycopy(Object src,int srcPos, Object dest, in ...

  9. 计算机程序的思维逻辑 (31) - 剖析Arrays

    数组是存储多个同类型元素的基本数据结构,数组中的元素在内存连续存放,可以通过数组下标直接定位任意元素,相比我们在后续章节介绍的其他容器,效率非常高. 数组操作是计算机程序中的常见基本操作,Java中有 ...

随机推荐

  1. USACO 2014 US Open Fair Photography /// 技巧

    题目大意: 给定n头奶牛 给定n头奶头所在位置和品种 品种只有G H两种 求一段区间的长度 要求区间内包含的品种满足各品种的数量相同 将一个品种的值设为1 另一个设为-1 假设 i<j 而 1~ ...

  2. 第二十五天 慵懒的投射在JDBC上的暖阳 —Hibernate的使用(四)

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/zwszws/article/details/28493209            6月4日.晴天. ...

  3. LeetCode Array Easy 1. Two Sum

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  4. 微信小程序の小程序事件流

    一.什么是事件? 事件是视图层到逻辑层的通讯方式:事件可以将用户的行为,反馈到逻辑层进行处理:事件可以绑定在组件上,触发事件后,就会执行逻辑层中对应的事件处理函数:事件对象可以携带额外信息. 二.事件 ...

  5. ArrayList的几种初始化方法

    1.使用Arrays.asList方法 ArrayList<Object> obj = new ArrayList<Object>(Arrays.asList(Object o ...

  6. 第四章 K8s部署安装

    一.kube-proxy开启ipvs的前置条件 //1.加载netfilter模块 modprobe br_netfilter //2.添加配置文件 cat > /etc/sysconfig/m ...

  7. compiz隐藏最大化窗口标题栏

    xfwm换了compiz试试,还行,挺方便.就是这个隐藏最大化窗口的标题栏没有现成的ui设置项,google到如下解决方案: 修改后立即生效. https://planetkris.com/2009/ ...

  8. vue项目从0开始记录

    1.安装vue-cli 2.通过脚手架进行项目的创建    4.配置第三方UI库快速开发(如ivew,element ui) 5.配置axios 库 一.安装vue-cli npm install - ...

  9. Ansible自动化部署K8S集群

    Ansible自动化部署K8S集群 1.1 Ansible介绍 Ansible是一种IT自动化工具.它可以配置系统,部署软件以及协调更高级的IT任务,例如持续部署,滚动更新.Ansible适用于管理企 ...

  10. leetcode-161周赛-5248-统计【优美子数组】

    题目描述: 自己的提交:超时: class Solution: def numberOfSubarrays(self, nums, k: int) -> int: dp = [0]* (len( ...