- 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
Fill elements in a Java float array in a specified range
Elements can be filled in a Java float array in a specified range using the java.util.Arrays.fill() method. This method assigns the required float value in the specified range to the float array in Java.
The parameters required for the Arrays.fill() method are the array name, the index of the first element to be filled(inclusive), the index of the last element to be filled(exclusive) and the value that is to be stored in the array elements.
A program that demonstrates this is given as follows −
Example
import java.util.Arrays; public class Demo { public static void main(String[] argv) throws Exception { float[] floatArray = new float[10]; float floatValue = 5.8F; int indexStart = 5; int indexFinish = 9; Arrays.fill(floatArray, indexStart, indexFinish, floatValue); System.out.println("The float array content is: " + Arrays.toString(floatArray)); } }
Output
The float array content is: [0.0, 0.0, 0.0, 0.0, 0.0, 5.8, 5.8, 5.8, 5.8, 0.0]
Now let us understand the above program.
First, the float array floatArray[] is defined. Then the Arrays.fill() method is used to fill the float array with value 5.8 from index 5(inclusive) to index 9(exclusive). Finally, the float array is printed using the Arrays.toString() method. A code snippet which demonstrates this is as follows −
float[] floatArray = new float[10]; float floatValue = 5.8F; int indexStart = 5; int indexFinish = 9; Arrays.fill(floatArray, indexStart, indexFinish, floatValue); System.out.println("The float array content is: " + Arrays.toString(floatArray));
- Related Articles
- Fill elements in a Java double array in a specified range
- Fill elements in a Java long array in a specified range
- Fill elements in a Java byte array in a specified range
- Fill elements in a Java char array in a specified range
- Fill elements in a Java int array in a specified range
- 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
- Java Program to fill elements in a byte array
- Style elements with a value within a specified range with CSS
- Style elements with a value outside a specified range with CSS
- Java Program to fill elements in an int array
- How to convert Float array list to float array in Java?
- Remove a range of elements from a LinkedList in Java
