Array in Java
Easy to difficult
Array 101
float array[]; /* and */ int foo()[] { ... } /* are discouraged */
float[] array; /* and */ int[] foo() { ... } /* are encouraged */To find the length of array, just use : arr.length;
ArrayType : Type of the array. This can be primitive ( int , long , byte ) or Objects ( String , MyObject , etc).
int numbers = new int[3];
int numbers = { 1, 2, 3 };
int numbers = new int[] { 1, 2, 3 };
int[][] number = { { 1, 2 }, { 3, 4, 5 } };
int[][] number = new int[5][];
int[][] number = new int[5][5];
float[] boats = new float[5];
String[] theory = new String[] { "a", "b", "c" };
Object[] dArt = new Object[] { new Object(),
"We love Stack", new Integer(3) };Copying Array
int[] a = { 4, 1, 3, 2 };
int[] b = a.clone();
// [4, 1, 3, 2]
int[] a = {4, 1, 3, 2};
int[] b = Arrays.copyOf(a, a.length);
// [4, 1, 3, 2]
int[] a = { 4, 1, 3, 2 };
int[] b = new int[a.length];
System.arraycopy(a, 0, b, 0, a.length);
// [4, 1, 3, 2]What is List
List is an interface, and the instances of List can be created by implementing various classes
Creating a List from an Array
ArrayIndex Out Of Bounds Exception
Arrays to Stream
Array to String
Sorting Arrays
Common Array functions Java
How do you change the size of an array?
Remove an element from an array
Using ArrayList
Using arraycopy
Comparing arrays for equality
Last updated
Was this helpful?