0

How to convert an String array to a float array? For example:

String[] arr = new String[] {"1.1","2.2","3.3","4.4","5.5"};

At the end it should be a float array.

Mehdi Rahimi
  • 1,453
  • 5
  • 20
  • 31
  • @jhamon does this work also for arrays – user18862161 Apr 19 '22 at 10:27
  • It works for array *elements*. You will need to create resulting array yourself and *fill* it with results of method mentioned in duplicate. – Pshemo Apr 19 '22 at 10:32
  • 1. Create a `float[]` with the same length as `arr`. 2. Iterate `arr`. 3. Use [`Float.parseFloat(String s)`](https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Float.html#parseFloat(java.lang.String)) on every string. 4. Add the result to the float array. – QBrute Apr 19 '22 at 11:00

0 Answers0