I have a list of numbers from a csv file that I have exported to an ArrayList. Now, the thing is that my ArrayList is in String and not in double. I have tried using
ArrayList<Double> arr = new ArrayList<Double>();`
but it gave me an error.
I want to remove any number in the ArrayList that is less than 0.1. Here is my code:
public class Example1
{
public static void main(String[] args) throws InvalidFormatException, IOException{
ArrayList arr=new ArrayList();
File f=new File("C:\\java\\marchcalllast.csv");
Scanner in=new Scanner(f).useDelimiter(",");
while(in.hasNext())
{
arr.add(in.next());
}
for (int i = 0; i < arr.size(); i++){
Double item = Double.valueOf(arr.get(i));
if (item < 0.1) {
arr.remove(i);
}
}
System.out.println(arr);
It gives me the following error:
Error: no suitable method found for valueOf(java.lang.Object) method java.lang.Double.valueOf(double) is not applicable (actual argument java.lang.Object cannot be converted to double by method invocation conversion) method java.lang.Double.valueOf(java.lang.String) is not applicable (actual argument java.lang.Object cannot be converted to java.lang.String by method invocation conversion)