Abnormal array

Common array abnormalities:

1, cross-border abnormal array subscript

 2, the array null pointer exception, which NullPointerException is divided into three kinds:

{class Exception1 public 
public static void main (String [] args) {
//. 1, superscripts array bounds exception: java.lang.ArrayIndexOutOfBoundsException
// int [] I = new new int [10];
// I [ 10] = 8; // the index bounds
// System.out.println (I [10]);

// 2, null pointer exception java.lang.NullPointerException
// first
// boolean [] b = new Boolean [. 3];
// B = null; // null pointer exception occurs here
// System.out.println (B [0]);

// second
// String [] str = new String [5] ;
// str [4] = new new String ( "AA"); // or written str [3] = "AA" , do not write an exception this one will be a null pointer
// System.out.println (str [4 ] .toString ());

// third
int [] [] j = new int [3] [];
j [1] [0] = 6; // first address is null, not find the specified value
}
}

Guess you like

Origin www.cnblogs.com/-lwl/p/10950571.html