Java Array Compiler
Practice Java arrays without installing a JDK. Pick a snippet below, hit Run, and edit it live in our Java 17 compiler. Every example is editable and runnable in the browser.
Run Java Array Compiler examples in the Java compiler
Examples included
Practical tips
- Use Arrays.toString(arr) to print arrays — direct printing shows hash codes.
- For 2D arrays, matrix.length is the number of rows; matrix[0].length is columns.
- Arrays.sort() is in-place. To get a sorted copy, clone first: int[] sorted = arr.clone(); Arrays.sort(sorted).
- Java arrays have a fixed size. For dynamic resizing use ArrayList.
Common questions
How do I declare an array in Java?
Use int[] arr = {1,2,3} for literal arrays, or int[] arr = new int[5] for a sized empty array.
How do I read an array from input?
Read the size with Scanner.nextInt(), then loop nextInt() to fill the array. See the "Read Array from Input" example.
Can I run 2D array programs in this compiler?
Yes. The 2D array example shows iteration over rows and columns and runs in your browser.
Practice related Java exercises · Browse Java programs with output