I’m trying to find and read a string from a text file using a “.equal” in java. I know that I can simply do this by using “.contain” instead, but I just want to know if there is anyway to find and read the line like this:
For example I have the following data in the text file:
ID1 123 123
ID2 125 136
Now
String ID="ID1";
while ((ss = buffered_reader.readLine()) != null){
if (ss.equals(ID+[anything])){do something} }
Why I want to this is to prevent getting result for entering just “ID”. So is there any way like a regex or something that can help ?
Clarification :
I want to find the exact match for the ID , for example :
if you enter ID1 then the program says : true
but false for entering just ID
if I use .contain the program finds the word ID1 or ID2 and because they contain “ID” , then it always returns a true value.
now I want to use .eqaual to find the exact match followed by anything
Try this:
The expresion
.*means any sequence of characters, even an empty sequence. So ifIDis “ID1” then it will match anystringthat begins with ID1.