I’m new to JAVA and I’m trying to read data from a .txt file. I’ve implemented a Scanner object ‘in’ Scanner in=new Scanner("file.txt");
and then down the code a while loop to traverse through the content of the file.There are multiple rows of data in the file and in each row there are three strings (security number ,First name ,Last name : 01 Thomas Anderson)
while(in.hasNext()){ String ss = in.next(); String FName=in.next(); String LName=in.next(); System.out.printf("SSN: %s, FirstName: %s, LastName: %s \n",ss,FName,LName); }
So,what does the hasNext() method do? Does it look for end of the row or for the last row in the file or…. ?
PLEASE elaborate on the working of the above snippet (mentioning the next() method too)
🙂
Related Posts:
- Exception in thread “main” java.util.NoSuchElementException
- NoSuchElementException with Java.Util.Scanner
- Rock, Paper, Scissors Game Java
- Why am I getting InputMismatchException?
- Scanner vs. BufferedReader
- What does Scanner input = new Scanner(System.in) actually mean?
- What’s the difference between next() and nextLine() methods from Scanner class?
- java.util.NoSuchElementException: No line found
- How do I use a delimiter with Scanner.useDelimiter in Java?
- What condition does while(true) test? When is it true and false?
- What does Scanner input = new Scanner(System.in) actually mean?
- java.util.NoSuchElementException – Scanner reading user input
- How would I use a while loop to keep requesting user input
- Reading a .txt file using Scanner class in Java
- Using a do-while loop to check a User’s input in Java
- How do I exit a while loop in Java?
- How to use a Do-while loop that continuously prompts a user?
- Multiple delimiters in Scanner class of Java
- How do I convert this for loop into a while loop?
- “Cannot be resolved to a type” when attempting to use Scanner
- Java Not Greater than Or Equal to Operator for Char Type
- Read next word in java
- How does the Java ‘for each’ loop work?
- What does “Could not find or load main class” mean?
- How do I create a file and write to it?
- When to use LinkedList over ArrayList in Java?
- How to convert a char to a String?
- How do you create a dictionary in Java? [closed]
- How do I declare and initialize an array in Java?
- Convert list to array in Java [duplicate]
- Convert String to double in Java
- Initialization of an ArrayList in one line
- “Exception in thread “main” java.lang.IndexOutOfBoundsException: Index: 0, Size: 0″ with ArrayList?
- Raising a number to a power in Java
- Running JAR file on Windows 10
- Iterate through a HashMap [duplicate]
- Double array initialization in Java
- I want to declare an empty array in java and then I want do update it but the code is not working
- Usage of @see in JavaDoc?
- Hadoop “Unable to load native-hadoop library for your platform” warning
- Eclipse: Java was started but returned error code=13
- Why java unknown: import org.apache.commons.codec.binary.Base64;?
- Extracting .jar file with command line
- Unable to create requested service [org.hibernate .engine.jdbc.env.spi.JdbcEnvironment]-MySQL
- Why do I get “Exception; must be caught or declared to be thrown” when I try to compile my Java code?
- Check jdk/JRE is installed and get path for jvm.dll
- What is Java String interning?
- Rename a file using Java
- What is “String args[]”? parameter in main method Java
- “A java exception has occurred” when opening .jar
- Spring Maven clean error – The requested profile “pom.xml” could not be activated because it does not exist
- Java Class File Editor
- Error Importing SSL certificate : Not an X.509 Certificate
- How do I draw a triangle?
- warning: [options] bootstrap class path not set in conjunction with -source 1.5
- “Actual or formal argument lists differs in length”
- TreeMap sort by value
- Encrypt Password in Configuration Files?
- IDEA: javac: source release 1.7 requires target release 1.7
- Can we write our own iterator in Java?
- local variables referenced from a lambda expression must be final or effectively final
- java.lang.IllegalMonitorStateException: object not locked by thread before wait()?
- WebServlet cannot be resolved to a type
- How do I print out the value of this boolean? (Java)
- How to add an object to an ArrayList in Java
- Getting warning “NDK is missing a ‘platforms” directory.’ with no NDK
- No appenders could be found for logger(log4j)?
- ArrayList<> cannot be resolved to a type
- Exception in thread “main” java.lang.StringIndexOutOfBoundsException: String index out of range: 0
- How do I call one constructor from another in Java?
- Does Java have something like C#’s ref and out keywords?
- How to upload a file and JSON data in Postman?
- What is the difference between i++ & ++i in a for loop?
- when to throw FileNotFoundException
- How to use ArrayUtils for array of objects, it doesn’t delete the content of an array
- The ResourceConfig instance does not contain any root resource classes
- Which exception to throw for invalid input which is valid from client perspective
- Efficient way to do batch INSERTS with JDBC
- wrong ELF class: ELFCLASS32
- Understanding BufferedImage.getRGB output values
- What is the purpose of creating static object in Java?
- How to print a method in java
- build-impl.xml:1031: The module has not been deployed
- Spring-Security-Oauth2: Full authentication is required to access this resource
- Why is System.out.print() not working?
- setMnemonic() and call a method by pressing the key
- What is `AnyType` in java generics
- “insufficient memory for the Java Runtime Environment ” message in eclipse
- How to ping an IP address
- The request was rejected because no multipart boundary was found in springboot
- Static Final Long serialVersionUID = 1L
- Which Eclipse IDE version to choose?
- Where can I download the jar for org.apache.http package?
- Java – ‘ ) ‘ expected error
- What is the size of a boolean variable in Java?
- Use CSS in Java Applications
- java.lang.ArrayIndexOutOfBoundsException: 2 [duplicate]
- Using the Pythagorean theorem with Java
- How do I enable index downloads in Eclipse for Maven dependency search?
- How to convert java.util.Date to java.sql.Date?