Java array declaration methods and java array declaration Methods
Java array definition declaration methods:
1. type name [] variable name = new type name [length];
2. type name [] variable name = {?,?,?};
3. type name [] variable name = new type name [] {?,?,?};
Sample Code:
Public class Example1 {public static void main (String [] args) {// Several methods defined by arrays // 1. type name [] variable name = new type name [length]; int [] a = new int [4]; a [0] = 1; a [1] = 2; a [2] = 3; a [3] = 4; System. out. println (a); System. out. println (a [0]); System. out. println (a [1]); System. out. println (a [2]); System. out. println (a [3]); // 2. type name [] variable name = {?,?,?}; Int [] B = {1, 2, 4}; System. out. println (B [0]); System. out. println (B [1]); System. out. println (B [2]); System. out. println (B [3]); // 3. type name [] variable name = new type name [] {?,?,?}; Int [] c = new int [] {1, 2, 3, 6}; System. out. println (c [0]); System. out. println (c [1]); System. out. println (c [2]); System. out. println (c [3]) ;}}
Three methods are displayed separately on the overview page:
1. type name [] variable name = new type name [length];
// 1. type name [] variable name = new type name [length]; int [] a = new int [4]; a [0] = 1; a [1] = 2; a [2] = 3; a [3] = 4; System. out. println (a); System. out. println (a [0]); System. out. println (a [1]); System. out. println (a [2]); System. out. println (a [3]);
Method 1:
2. type name [] variable name = {?,?,?};
// 2. type name [] variable name = {?,?,?}; Int [] B = {1, 2, 4}; System. out. println (B [0]); System. out. println (B [1]); System. out. println (B [2]); System. out. println (B [3]);
Method 2:
3. type name [] variable name = new type name [] {?,?,?};
// 3. type name [] variable name = new type name [] {?,?,?}; Int [] c = new int [] {1, 2, 3, 6}; System. out. println (c [0]); System. out. println (c [1]); System. out. println (c [2]); System. out. println (c [3]);
Method 3: