ArrayList<String> list=new ArrayList<String>();
try {
Scanner scanner=new Scanner(new File("Info.csv"));
scanner.useDelimiter(",");
while(scanner.hasNext())
{
list.add(scanner.next());
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
for(String s:list)
{
if(s.toLowerCase().equals("test"))
{
System.out.println(s);
}
}
If I remove the 'if' statement and print out each 's' value. It will happily return every single value properly on a new line without any trailing white spaces or anything that could potentially cause it to return false due to actually being unequal.
Thing is, the string I am comparing against in this case "test" does quite literally exist in the 'list' (Even checked the console when printing each 's' value to make sure it's there)
How can it return false when logically it should return true as soon as the string comes up?
I also tested by using .contains instead of .equals and it returned the value as expected...But it also returned another value that comes before it, which doesn't even in the slightest contain 'test'. All of this is confusing me a lot right now, any solutions or possible alternatives would be appreciated.
Just a little basic info of what's inside the csv file. It's just either numbers or words, and properly separated by a comma (Proven by the fact that when printing each 's' value they all print correctly on a new line)
Example:
test,4,,Unknown
stuff,0,12/15/2015,183
things,0,12/15/2015,183
Yes, some values will return "" (The part in the double comma) and that's fine, and they get printed as expected which is what I want. In the end, each line will contain 4 values which is what I want.
This is just a small part of what it is, mine is around 850+ pieces of separate values.
EDIT: Solved by replacing the delimiter with "[n,]"
Aucun commentaire:
Enregistrer un commentaire