java - Infinite loop stuck -


i have been looking @ bit.. , put in item = null see happens.. bit of code keeps getting stuck in infinite loop. item equal null , should kick out of loop keeps running.

 arraylist<string> collection = new arraylist();   scanner arrayread = new scanner(new filereader("salesstar.txt"));     //iterate through file put arraylist    string item = null;    while( item != null ) {                   item = arrayread.next();        collection.add(item);               }     arrayread.close();      system.out.println(collection);    system.out.println(item); 

it not enter loop

   string item = null; 

in line setting item null

   while( item != null )  

but in next line set condition item!=null whill false, never enter loop

to working can following (as explained)

   while( arrayread.hasnext() ) {                   item = arrayread.next();        collection.add(item);               } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -