JAVA ARRAY CHEAT SHEET | QA SDET | TEST AUTOMATION

Опубликовано: 03 Июль 2026
на канале: Viplove QA - SDET
635
like

Java Array Cheat Sheet - Summary Format

1. Array Definition:

Arrays are fixed-size, index-based data structures that store similar types of data.

Example declarations:

int[] a = new int[10];

char[] c = new char[15];

String[] s = new String[20];



2. Array Structure:

Indexing starts at 0. For example: int[] arr = {21, 15, 37, 53, 17}


3. Array Declaration:

Two ways:

int[] arr;

int arr[];



4. Array Initialization:

Step-by-step: arr[0] = 21; arr[1] = 15; ...

With new: int[] arr = new int[]{21, 15, 37, 53, 17};

Directly: int[] arr = {21, 15, 37, 53, 17};


5. Array Traversal:

Using for loop:

for (int i = 0; i arr.length; i++)
System.out.println(arr[i]);

Using enhanced for loop:

for (int i : arr)
System.out.println(i);


6. Multidimensional Arrays:

2D: int[][] arr = {{1,2,3},{4,5,6},{7,8,9}};

3D: int[][][] arr = {{{1,2,3},...}, ...}

Jagged: Arrays of different lengths inside a 2D array


7. Anonymous Arrays:

Used without a name: new int[]{1, 2, 3, 4, 5};


8. Array to List Conversion:

List String list = Arrays.asList("One", "Two", "Three");


9. Array to Stream:

IntStream stream = Arrays.stream(new int[]{1, 2, 3});


10. Array Length:

Use arr.length to get size


11. java.util.Arrays Methods:

sort() - Sort array

stream() - Convert to stream

spliterator() - Get spliterator

setAll() - Initialize all elements

fill() - Fill with a value

copyOf() - Copy array

asList() - Convert to list

binarySearch() - Search value


12. Pros:

Easy to implement

Supports primitives and references

Fast data retrieval


13. Cons:

Fixed size

Not type safe

No built-in methods