I am new here!
I am doing a school project where I take a .csv file as input and read every line of values and store them into a String[], and then create an ArrayList.
The CSV file has some temperature measurements and I'm required to make filters for the different temperature measurements. What I want to know if there is a way to make the condition of an if statement the value of a string.
Since there are different ways to filter the information (>,<,>=,<=, from int x to int y) I want to create a method that concatenates a string that creates the condition the user is looking for;
- Prompts user to choose what data from the array he wants to filter by.
(For instance option 3, which means its the data stored in String[2])
- Then asks the user to choose how he wants to filter: >,<,>=,<=, from int x to int y.
Finally asks the remaining value to finish the comparison.
From these prompts we could build:
String a = String[2] + (comparison operator) + comparison value.
For example
a = String[2] + " > 20"
Then I want to use the 'a' like this: if(a){}
Where the console should read this as: - - - - - - - if(Double.valueOf(String[2]) > 20){}
My IDE is BlueJ which tells me incompatible types: java.lang.String cannot be converted to boolean. You may wonder why I use a String[] if I'm comparing double values,
Thanks in advance and my apologies if my idea is preposterous or not clear.