Breaking from a hasnext in scanner

while(sc.hasNext()){
ar.add(sc.nextLong());

        if(sc.nextLong()=='\n')
        break;
    }

i want to implement something like this so that my command line input breaks on inputting a blank line but its running an infinite loop instead

Use sc.nextLine() and check if that line is just empty or not. If it is, break, else convert it to long and store in an array. No need to use has Function . Just loop while(true)

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.