fill is a static method of the java.util.Arrays class. That is why it is invoked that way. If it were an instanced method of the actual Array class (it's not due to the way arrays are handled in Java) then you could call it as you indicated. It’s typically faster to allocate all the memory at once and assign a new array than it is to iterate over an existing array which is partly why it was designed this way. The Array class in Java is designed to be simple and lightweight. https://www.geeksforgeeks.org/static-methods-vs-instance-methods-java/ Answer from MrSloppyPants on reddit.com
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Arrays.html
Arrays (Java Platform SE 8 )
October 20, 2025 - Java™ Platform Standard Ed. 8 ... This class contains various methods for manipulating arrays (such as sorting and searching).
🌐
DZone
dzone.com › data engineering › data › top 10 methods for java arrays
Top 10 Methods for Java Arrays
September 18, 2013 - The following are top 10 methods for Java Array. They are the most voted questions from stackoverflow. 0. Decalre an array String[] aArray = new String[5];...
Discussions

Why cant we call methods in the array subclass using the name of an array in Java?
fill is a static method of the java.util.Arrays class. That is why it is invoked that way. If it were an instanced method of the actual Array class (it's not due to the way arrays are handled in Java) then you could call it as you indicated. It’s typically faster to allocate all the memory at once and assign a new array than it is to iterate over an existing array which is partly why it was designed this way. The Array class in Java is designed to be simple and lightweight. https://www.geeksforgeeks.org/static-methods-vs-instance-methods-java/ More on reddit.com
🌐 r/learnprogramming
5
15
August 23, 2024
Do Java's regular arrays have built in methods? - Stack Overflow
I know that a regular Java array int[] arr = new int[5]; lives in the heap and therefore it is considered as an object. Although it is considered as an object it is different from other Java obects More on stackoverflow.com
🌐 stackoverflow.com
Creating an array method java - Stack Overflow
Here I need to write a method called powArray that takes a double array a and returns a new array that contains the elements of a squared. Generalize it to take a second argument and raise the elem... More on stackoverflow.com
🌐 stackoverflow.com
[JAVA] Arrays. ELI5 please.
Think of an array kind of like the cabinets in your kitchen, all in a line. Each cabinet has a specific location in your kitchen. If you were to tell someone where to find the cups when they're over at your house, you might say "They're in the cabinet over the stove, on the left". Your cabinets are used for storage of your dishes and other kitchen items, and they can be organized a certain way to make finding what you need easier. A one dimensional array is essentially a line of "cabinets" that you can store data in, where each cabinet has its own index, or location, that you reference it by. An array can be unsorted or sorted, and many algorithms exist to sort them, with some being fast, and some requiring very little extra memory. Something like .length or .size simply returns the amount of cabinets in your kitchen, or in programming terms, the number of spaces in your array. You can also make a two dimensional array, which you can think of like a grid of cubby holes at a pre-school, or more mathematically, as a matrix. These work exactly the same as a 1D array, but each element has two indexes instead of one, like an X and Y coordinate on graph paper. An array is stored linearly in memory and its indexes usually start at zero. The following example is how to create an array and fill it with numbers using Java. int[] myArray = new int[10]; //Creates an array of size 10 to store integers for(int i = 0; i < myArray.length; i++) { myArray[i] = i; } //myArray.length = 10, i = 0, loop until i > 9 //On each iteration, myArray at index i will contain the current value of i //When this loop finishes, myArray will contain 0,1,2,3,4,5,6,7,8,9 in that order Arrays are the simplest data structure you will be dealing with, but they are incredibly useful and have a huge amount of applications. Many complex data structures use arrays in some way. For example, you can represent a graph structure as a matrix, or two dimensional array, of connected edges. You can efficiently sort data without using any extra memory using a heap structure, which at its most basic form is just an array that can be sorted in place. Once you grasp arrays, you will be able to grasp the more complex structures much more easily. If there is anything else I can help you with, please let me know. More on reddit.com
🌐 r/learnprogramming
14
3
May 13, 2013
🌐
Tutorialspoint
tutorialspoint.com › home › java › java arrays
Java Arrays
September 1, 2008 - Discover how to work with arrays in Java, including declaration, initialization, and manipulation methods.
🌐
Jenkov
jenkov.com › tutorials › java › arrays.html
Java Arrays
April 24, 2019 - You can use the elements in a Java array just like if they were ordinary variables. You can read their value, assign values to them, use the elements in calculations and pass specific elements as parameters to method calls.
🌐
W3Schools
w3schools.com › java › java_ref_arrays.asp
Java Arrays Reference
A list of popular methods of the Arrays Class can be found in the table below: The length property is a built-in Java property, and does not belong to the Arrays class.
🌐
Reddit
reddit.com › r/learnprogramming › why cant we call methods in the array subclass using the name of an array in java?
r/learnprogramming on Reddit: Why cant we call methods in the array subclass using the name of an array in Java?
August 23, 2024 -

why do we have to do:

Arrays.fill(list, 5);

instead of

list.fill(5);

I thought that arrays are objects variables in Java, and usually I can call on a non static instance method using the name of the object.

Top answer
1 of 5
19
fill is a static method of the java.util.Arrays class. That is why it is invoked that way. If it were an instanced method of the actual Array class (it's not due to the way arrays are handled in Java) then you could call it as you indicated. It’s typically faster to allocate all the memory at once and assign a new array than it is to iterate over an existing array which is partly why it was designed this way. The Array class in Java is designed to be simple and lightweight. https://www.geeksforgeeks.org/static-methods-vs-instance-methods-java/
2 of 5
9
Others have already said why you have to do this, but I'll try and explain more of the reasoning behind it: From the very beginning of the Java language, one of its design goals was to implement as much functionality as possible in the Java language itself rather than depending on native code. For instance, the ArrayList and HashMap classes are made up of ordinary Java code, and (now that the JDK is open-source) you can go and read them yourself to see how they work. But arrays are kind of special. The String class is an ordinary Java class defined in a source file called String.java (with a bit of special treatment by the JVM). But there is no source code file that corresponds to the String[] array class. The compiler and JVM just have a general rule that says "for every type T, there is also an array type T[]. But there is no way of writing Java code that adds methods to String[] or any other type. Any methods or properties of arrays have to be treated specially by both the Java compiler and the JVM. So if the language designers want to add a useful method like fill that can operate on arrays, they have to either write a bunch of "magic" special-case code that behaves unlike normal Java code, or they can just write an ordinary Java static method that just happens to live in a "utility" class called Arrays. The latter is simpler, so it's what they chose to do. Only the minimal set of fields/methods are implemented directly on arrays. And even then, you can find room to quibble over what the ideal design looks like. On the one hand, maybe clone() was unnecessary because Arrays.copyOf can do the same job. On the other hand, maybe arrays should have had proper equals/hashCode implementations that actually look at the array contents, instead of what they currently have which just compares based on object identity. But oh well, life is full of compromises.
Find elsewhere
🌐
Codecademy
codecademy.com › learn › learn-java › modules › java-two-dimensional-arrays › cheatsheet
Learn Java: Two-Dimensional Arrays Cheatsheet | Codecademy
In Java, initializer lists can be used to quickly give initial values to 2D arrays. This can be done in two different ways. If the array has not been declared yet, a new array can be declared and initialized in the same step using curly brackets. If the array has already been declared, the new keyword along with the data type must be used in order to use an initializer list · // Method ...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › reflect › Array.html
Array (Java Platform SE 8 )
October 20, 2025 - Java™ Platform Standard Ed. 8 ... The Array class provides static methods to dynamically create and access Java arrays.
🌐
GeeksforGeeks
geeksforgeeks.org › java › array-class-in-java
Arrays Class in Java - GeeksforGeeks
The Arrays class in the java.util package is a utility class that provides a collection of static methods for performing common operations on Java arrays, such as sorting, searching, comparing and converting arrays to strings.
Published   November 13, 2025
🌐
Programiz
programiz.com › java-programming › arrays
Java Array (With Examples)
We can use loops to access all the elements of the array at once. In Java, we can also loop through each element of the array.
🌐
Baeldung
baeldung.com › home › java › java array › guide to the java.util.arrays class
Guide to the java.util.Arrays Class | Baeldung
April 4, 2025 - In this article, we learned how some methods for creating, searching, sorting and transforming arrays using the java.util.Arrays class.
🌐
EPAC
lira.epac.to › DOCS-TECH › Programming › Java › Java Arrays, Objects, Methods.pdf pdf
Java Arrays, Objects, Methods
Write a Java class named Arrays.java. This class should have the following ... Definition: An object is a software bundle of fields and related methods.
🌐
Oracle
docs.oracle.com › javase › specs › jls › se7 › html › jls-10.html
Chapter 10. Arrays
September 16, 2025 - In the Java programming language, arrays are objects (§4.3.1), are dynamically created, and may be assigned to variables of type Object (§4.3.2). All methods of class Object may be invoked on an array.
🌐
Oracle
docs.oracle.com › en › java › javase › 23 › docs › api › java.base › java › util › Arrays.html
Arrays (Java SE 23 & JDK 23)
October 17, 2024 - java.util.Arrays · public final class Arrays extends Object · This class contains various methods for manipulating arrays (such as sorting and searching). This class also contains a static factory that allows arrays to be viewed as lists. The methods in this class all throw a NullPointer...
🌐
Codecademy
codecademy.com › docs › java › arrays
Java | Arrays | Codecademy
October 23, 2023 - Java includes an Arrays class in java.util that provides a number of static methods for manipulating arrays.
🌐
Codecademy
codecademy.com › learn › learn-java › modules › learn-java-arrays-and-arraylists › cheatsheet
Learn Java: Arrays and ArrayLists Cheatsheet | Codecademy
Arrays are fixed in size and their elements are ordered. ... Using the {} notation, by adding each element all at once. Using the new keyword, and assigning each position of the array individually.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Array methods
That’s natural, because delete obj.key removes a value by the key. It’s all it does. Fine for objects. But for arrays we usually want the rest of the elements to shift and occupy the freed place. We expect to have a shorter array now. So, special methods should be used.