Lecture 16

来源:互联网 发布:手动安装windows补丁 编辑:程序博客网 时间:2024/03/29 15:34

CS106A Lecture 17

ARRAY

matrix 2d array

2*3

int[][] Matrix = new int[2][3];

Matrix[0][1] = 5;

Matrix[0] int[]

for(int i=0; i<2; i++){    for(int j=0; j<3; j++){        Matrix[i][j]=1;    }}

matrix 3d array

2*3*100

int[][][] Matrix = new int[2][3][100];

ArrayList

import java.util.*;

template

  • 1.5
    • 5.0
  • 1.6
    • 6.0
  • 1.x
    • x.0
  • Java 5.0+

boolean add(<T> element)

  • think as a parameterised type; this is just getting replaced with whatever type you instantiate your ArrayList to be

ArrayList<String> sList = new ArrayList<String>();

boolean add(String element)

Methods in the ArrayList Class

  • add
  • remove
  • clear
  • size
  • get
  • set
  • indexOf
  • isEmpty

Special

ArrayList hold objects

primitive

  • int
  • duoble
  • boolean
  • char

class “wrapper”

  • Double
  • Boolean
  • Character

int x=5;

BOXING

Integer y = new Integer(x);

UNBOXING

int z = y.intValue();


  • changed in java 5.0

自动装箱/解箱