I am new to Java and am writing a code which checks if an ID exists in a log file or not. If the ID is present in log file then it should print that ID already exist. But if it doesnt exist then it should do some task.

I have a string p1 = 1234

and wants to check if that string exist in log file or not.

```
p1 = 1234;
Scanner scanner=new Scanner("sample.log");
While(scanner.hasNextLine()){
if(p1.equals(scanner.nextLine().trim())){
 system.out.println("ID already exist")}
else{system.out.println("ID not present ")}

```

my sample.log file has some text like:

21 oct 2019, [WARN], 2324

21 oct 2019, [WARN], 1234

21 oct 2019, [INFO], 3343 and so on.