- 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
What does the method fill(obj[], int fromIndex, int toIndex, int val) do in java?
The fill(object[] a, int fromIndex, int toIndex, object val) method of the class java.util.Arrays assign the specified Object reference to each element of the specified range of the specified array of objects. The range to be filled extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be filled is empty)
Example
import java.util.Arrays; public class ArrayDemo { public static void main(String[] args) { Object arr[] = new Object[] {1.2, 5.6, 3.4, 2.9, 9.7}; System.out.println("Actual values: "); for (Object value : arr) { System.out.println("Value = " + value); } Arrays.fill(arr, 1, 3, 12.2); System.out.println("New values after using fill() method: "); for (Object value : arr) { System.out.println("Value = " + value); } } }
Output
Actual values: Value = 1.2 Value = 5.6 Value = 3.4 Value = 2.9 Value = 9.7 New values after using fill() method: Value = 1.2 Value = 12.2 Value = 12.2 Value = 2.9 Value = 9.7
- Related Articles
- What does the method fill(int[], int fromIndex, int toIndex, int val) do in java?
- What does the method sort(obj[] a, int fromIndex, int toIndex) do in java?
- What does the method sort(int[] a, int fromIndex, int toIndex) do in java?
- What does the method removeRange(int fromIndex, int toIndex) do in java?
- What does the method fill(int[], int val) do in java?
- What does the method set(int, obj o) do in java?
- What does the method copyOfRange(int[] original, int from, int to) do in java?
- What does the method equals(int[] a1, int[] a2) do in java?
- What does the method copyOf(int[] original, int newLength) do in java?
- What does the method fill(obj[], object val) do?
- What does the method remove(int) do in java?
- What does the method int capacity() do in java?
- What does the method get(int) do in java?
- What does the method hashCode(int[] a) do in java?
- What does the method sort(int[] a) do in java?

Advertisements