java数组的几种形式——java编程思想01
廢話不說,先來代碼!
package com.dongruan.practice;
import org.hibernate.dialect.H2Dialect;
import com.sun.jndi.url.dns.dnsURLContext;
class Weeble{
}
public class ArraySize {
public static void main(String[] args) {
Weeble[] a;//null handle---------1
Weeble[] b=new Weeble[5];//null handles-------2
Weeble[] c=new Weeble[4];
for (int i = 0; i < c.length; i++)
c[i]=new Weeble();
Weeble[] d={new Weeble(),new Weeble(),new Weeble()};//--------------3
System.out.println("b.length="+b.length);
for (int i = 0; i < b.length; i++) {
System.out.println("b["+i+"]="+b[i]);
System.out.println("c.length="+c.length);
System.out.println("d.length="+d.length);
a=d;
System.out.println("a.length="+a.length);
a=new Weeble[]{
new Weeble(),new Weeble()
};
System.out.println("a.length="+a.length);
int[] e;//----------1
int[] f = new int[5];//-------------2
int[] g=new int[4];
int[] h={11,47,93};//-------------3
for (int j = 0; j < g.length; j++)
System.out.println("f["+i+"]="+f[i]);
System.out.println("g.length="+g.length);
System.out.println("h.length="+h.length);
e=h;
System.out.println("e.length="+e.length);
e=new int[]{1,2};
System.out.println("e.length="+e.length);
}
}
}
?
如上1,2,3;再說一下概念;
1、訪問速度快,大小確定了。
對于Java 來說,為保存和訪問一系列對象
(實際是對象的句柄)數組,最有效的方法莫過于數組。數組實際代表一個簡單的線性序列,它使得元素的
訪問速度非常快,但我們卻要為這種速度付出代價:創建一個數組對象時,它的大小是固定的,而且不可在
那個數組對象的“存在時間”內發生改變。
?2、基礎類型不能放入集合,數組可以。
對于Java 來說,為保存和訪問一系列對象
(實際是對象的句柄)數組,最有效的方法莫過于數組。數組實際代表一個簡單的線性序列,它使得元素的
訪問速度非常快,但我們卻要為這種速度付出代價:創建一個數組對象時,它的大小是固定的,而且不可在
那個數組對象的“存在時間”內發生改變。
?
轉載于:https://www.cnblogs.com/daguozb/p/9633001.html
總結
以上是生活随笔為你收集整理的java数组的几种形式——java编程思想01的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python学习【day02】-str类
- 下一篇: 《DSP using MATLAB》Pr