java.util.scanner - Can I create a String variable that will always be the newest nextLine() Scan? -


because creating new string variable next line stored next line of whatever printout is, there way me create new string variable newest nextline()? want don't have keep making new strings collect each new line of input.

thanks help!

yes, example below:

scanner scan = new scanner(system.in);   out.println("enter something: "); //user enters "some" string scaninfo = scan.nextline();  out.println(scaninfo); //outputs "some"   out.println("enter something: "); //user enters "thing" scaninfo = scan.nextline();  out.println(scaninfo); //outputs "thing" 

just make sure know being rewritten every time not able access again. careful .nextline , .nextint (as wont able save .nextint string variable)

another idea (not sure exact implementation looking for) use stack, because can keep track of of scanned in information , can pop off recent scanned value


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -