Question

I am using method startsWith to find out, whether my string starts with desired string. Example:

       for(int i=0;i<tokens.length;i++){
           if(tokens[i].startsWith(ColumnName)){
                tokens[i]="";

           }

In tokens[i] there is a string "info REAL", in ColumnName, there is a string "info". In this comparsion, every time i get false. It is unbelivable, but even when i print it, it is like - tokens[i]:info REAL, startsWith:info, result:false...

I don't see any mistake here, you do? There is no TYPO in my program, I am 100% sure theese values are here correctly.

Thanks

Was it helpful?

Solution

check for spaces in the strings, its easy to overlook them in the console output.

e.g. "info REAL" vs "info " or "info REAL" vs " info"

OTHER TIPS

Maybe it's caused by whitespaces. Have you tried trimming your strings before doing that ?

Something like tokens[i].trim().startsWith(ColumnName.trim())

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top