To convert a list of floats to a list of strings in Java, you can use a loop to iterate over each float and convert it to a string using the Float.toString()
method.
In this example,
floatList
.Float.toString()
method.import java.util.ArrayList;
import java.util.List;
class Main {
public static void main(String[] args) {
List<Float> floatList = List.of(1.1f, 2.2f, 3.3f, 4.4f, 5.5f);
List<String> stringList = new ArrayList<>();
for (Float num : floatList) {
stringList.add(Float.toString(num));
}
System.out.println("List of strings: " + stringList);
}
}
List of strings: [1.1, 2.2, 3.3, 4.4, 5.5]
In this tutorial, we learned How to Convert a List of Floats to a List of Strings in Java language with well detailed examples.