I'm working on this script to compare elements sequentially in a list/array in Java. Essentially the code takes in a CSV, converts it to a list and iterates over the list's size. When I attempt a comparison between the values I run into an error I can't figure out in this case:
Exception in thread "main" java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Float (java.lang.String and java.lang.Float are in module java.base of loader 'bootstrap')
at list.main(list.java:22)
The code is:
public class list{
public static void main(String[] args){
System.out.println("Enter your filename");
Scanner inputValue = new Scanner(System.in);
String fileLocation = inputValue.nextLine();
try {
String checkvalue = new String(Files.readAllBytes(Paths.get(fileLocation)));
ArrayList<Float> listValues = new ArrayList(Arrays.asList(checkvalue.split("[\\r\\n]+")));
System.out.println(listValues);
for (int i = 0; i < listValues.size(); i++){
System.out.println(listValues.get(i));
float valueA = listValues.get(i);
float valueB = listValues.get(i+1);
if (valueA <= valueB){
System.out.println("True");
}
}
}
catch (IOException e){
e.printStackTrace();
}
}
}