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
Calling subclass methods on an array of superclass objects
can you show the code for the other two classes? More on reddit.com
🌐 r/javahelp
12
2
April 19, 2018
🌐
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
Arrays Loop Through an Array Real-Life Examples Multidimensional Arrays Code Challenge · Java Methods Java Method Challenge Java Method Parameters
🌐
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)
In this tutorial, we will learn to work with Java arrays. We will learn to declare, initialize, and access array elements with the help of examples. An array is a collection of similar data types.
🌐
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.