You do know that you can create arrays of variable size by using a variable as the array length?

 public float[] newFloatArray(int size) {
     float[] array = new float[size];
     return array;
 }

Filling the array can be done with a loop or using the JRE supplied Arrays class helper methods. You will need to handle the first and last index in the array separately:

 public float[] newGolfArray(int size) {
     float[] array = new float[size];
     Arrays.fill(array, 1F);
     array[0] = 4F;
     array[size - 1] = 2F;
     return array;
 }
Answer from Durandal on Stack Overflow
🌐
Huda Tutorials
hudatutorials.com › java › basics › java-arrays › java-float-array
Java float Array - float Array in Java
July 16, 2021 - In Java any value declared with decimal point is by default of type double. Suppose we have to assign float value then we must use f or F literal to specify that current value is float. Specify E or e for values which contain exponent.
🌐
TutorialsPoint
tutorialspoint.com › java › util › arrays_fill_float.htm
Java Arrays fill(float[], float) Method
Using fill(float[], float) method, we're filling the array with a give value and then updated array elements are printed again. package com.tutorialspoint; import java.util.Arrays; public class ArrayDemo { public static void main(String[] args) { // initializing float array float arr[] = new float[] { 10.0f, 20.0f, 15.0f }; // let us print the values System.out.println("Actual values: "); for (float value : arr) { System.out.println("Value = " + value); } float replacement = 0.0f; // using fill for placing value Arrays.fill(arr, replacement); // let us print the values System.out.println("New values after using fill() method: "); for (float value : arr) { System.out.println("Value = " + value); } } }
🌐
GeeksforGeeks
geeksforgeeks.org › java › array-getfloat-method-in-java
Array getFloat() Method in Java - GeeksforGeeks
November 30, 2018 - // Java code to demonstrate getFloat() method of Array class import java.lang.reflect.Array; public class GfG { // main method public static void main(String[] args) { // Declaring and defining a float array float a[] = { 1.0f, 2.0f, 3.0f }; try { float x = Array.getFloat(a, 4); } catch (Exception e) { System.out.println("Exception : " + e); } } } Output:
🌐
Java by examples
javaquery.com › 2015 › 10 › how-to-initialize-float-or-float-array.html
Java by examples: How to Initialize float or Float array in declaration?
Print value of float[] 10.1 20.2 30.3 Print value of Float[] 10.1 20.2 null References How to Initialize int or Integer array in declaration? How to Initialize long or Long array in declaration? How to Initialize double or Double array in declaration? How to Initialize boolean or Boolean array in declaration? Tags: Array · Array · Newer Post Home Older Post · Subscribe to: Post Comments ( Atom ) Follow @javaQuery ·
🌐
YouTube
youtube.com › watch
How to store float values in Java Array? | Java Array Handling: Storing float Values | Java Tutorial - YouTube
Welcome to this Java tutorial where we explore how to store `float` values in Java arrays!In Java programming, arrays are powerful data structures that allow...
Published   October 10, 2015
🌐
DataCamp
datacamp.com › doc › java › float
float Keyword in Java: Usage & Examples
This example demonstrates the use of a float array. The array floatArray is initialized with five float values.
🌐
Scijava
javadoc.scijava.org › SciJava › org › scijava › util › FloatArray.html
FloatArray (SciJava Javadocs 0-SNAPSHOT API)
java.util.AbstractList<BaseType> ... Subclasses: FloatColumn · public class FloatArray extends AbstractPrimitiveArray<float[],Float> An extensible array of float elements....
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › how-to-convert-float-array-list-to-float-array-in-java
How to convert Float array list to float array in Java?
JavaObject Oriented ProgrammingProgramming · Let us first create a float array list − · ArrayList < Float > arrList = new ArrayList < Float > (); arrList.add(5.2 f); arrList.add(10.3 f); arrList.add(15.3 f); arrList.add(20.4 f); Now, convert the float array list to float array.
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Convert Float ArrayList to Primitive Array in Java - Java Code Geeks
June 11, 2024 - The MutableFloatList is then converted to a primitive float array using the toArray method. The output is: ... Efficiency: Eclipse Collections provides optimized data structures and methods for handling primitive types, resulting in better performance. Simplicity: Using Collectors2 simplifies the conversion process by reducing boilerplate code. Flexibility: Eclipse Collections offers a wide range of utilities and data structures that enhance Java’s standard collection framework.
🌐
TutorialsPoint
tutorialspoint.com › java › util › arrays_tostring_float.htm
Java.util.Arrays.toString(float[ ]) Method
package com.tutorialspoint; import java.util.Arrays; public class ArrayDemo { public static void main(String[] args) { // initializing float array float[] f1 = new float[] { 1.2f, 9.7f, 3.4f }; // let us print all the elements available in list System.out.println("The array is:"); for (float number : f1) { System.out.println("Number = " + number); } System.out.println("The string representation of array is:"); System.out.println(Arrays.toString(f1)); } }
🌐
Guava
guava.dev › releases › 19.0 › api › docs › com › google › common › primitives › Floats.html
Floats (Guava: Google Core Libraries for Java 19.0 API)
Returns the values from each provided array combined into a single array. For example, concat(new float[] {a, b}, new float[] {}, new float[] {c} returns the array {a, b, c}. ... Returns a serializable converter object that converts between strings and floats using Float.valueOf(java.lang.String) ...
🌐
Baeldung
baeldung.com › home › java › java array › converting float arraylist to primitive array in java
Converting Float ArrayList to Primitive Array in Java | Baeldung
March 7, 2025 - The Collection API provides a nice method to convert a List into an array but doesn’t handle unboxing. However, it’s useful enough to consider it in this article: @ParameterizedTest @MethodSource("floatListProvider") void givenListOfWrapperFloat_whenConvertToWrapperArray_thenGetCorrectResult(List<Float> floats) { Float[] actual = floats.toArray(new Float[0]); assertSequences(floats, actual); }
🌐
Processing
processing.github.io › processing-javadocs › core › processing › data › FloatList.html
FloatList
Returns the actual array being used to store the data. For advanced users, this is the fastest way to access a large list. Suitable for iterating with a for() loop, but modifying the list will have terrible consequences. public java.util.Iterator<java.lang.Float> iterator()
🌐
Javadoc.io
javadoc.io › static › org.ode4j › core › 0.5.0 › org › ode4j › ode › internal › cpp4j › java › FloatArray.html
FloatArray (core 0.5.0 API)
org.ode4j.ode.internal.cpp4j.java.FloatArray · public class FloatArray extends Object · Class to simulate pointer operations on float arrays. Author: Tilmann Zaeschke · clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait ·
🌐
GeeksforGeeks
geeksforgeeks.org › java › array-setfloat-method-in-java
Array setFloat() method in Java - GeeksforGeeks
November 30, 2018 - // Java code to demonstrate // setFloat() method of Array class import java.lang.reflect.Array; public class GfG { // main method public static void main(String[] args) { // Declaring and defining float array float f[] = { 1.0f, 2.0f, 3.0f }; System.out.print("Before Set : "); // printing the array for (float x : f) { System.out.print(x + " "); } float value = 4.0f; // setFloat method of class Array Array.setFloat(f, 1, value); System.out.print("\nAfter Set : "); // printing array for (float x : f) { System.out.print(x + " "); } } } Output: Before Set : 1.0 2.0 3.0 After Set : 1.0 4.0 3.0 Program 2: To demonstrate java.lang.NullPointerException ·
🌐
Oracle
docs.oracle.com › javase › specs › jls › se7 › html › jls-10.html
Chapter 10. Arrays
September 16, 2025 - The value of an array component of type float is always an element of the float value set (§4.2.3); similarly, the value of an array component of type double is always an element of the double value set.