- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to fill array values in Java?
Let us first create an int array −
int[] arr = new int[10];
Now, fill array values. Here, the numbers get added from the index 2 to 7 −
Arrays.fill(arr, 2, 7, 100);
Example
import java.util.Arrays; public class Demo { public static void main(String[] args) { int[] arr = new int[10]; System.out.println("Array = "+Arrays.toString(arr)); Arrays.fill(arr, 2, 7, 100); System.out.println("Fill = "+Arrays.toString(arr)); } }
Output
Array = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] Fill = [0, 0, 100, 100, 100, 100, 100, 0, 0, 0]
- Related Articles
- Fill missing numeric values in a JavaScript array
- How to detect duplicate values in primitive Java array?
- Java Program to fill elements in a float array
- Java Program to fill elements in a short array
- Java Program to fill elements in a char array
- Java Program to fill elements in a long array
- Working with Array.setInt to fill an array in Java
- Java Program to fill elements in a byte array
- Java Program to fill elements in an int array
- How to pull distinct values from an array in java?
- Default array values in Java
- Java Program to fill an array with random numbers
- Use reflection to create, fill, and display an array in Java
- Python - How to fill NAN values with mean in Pandas?
- Create an array class with possibly masked values and fill in the masked values in Numpy

Advertisements