[hotjoe.com] HotJoe Java Help Forums
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Visit java.com
Missing post? - see this post about spam for more information.
(How to Use) The Scanner Class  XML
Forum Index » How To Articles
Author Message
destin

Newbie
[Avatar]
Joined: 01/07/2006 19:13:04
Messages: 224
Offline

The Scanner Class
The Scanner class is a class used for "scanning" primitive types and
Strings. It can be used to get input from an InputStream, to parse through
a String of text or to read from a file.

Parsing Through a String
The constructor that we will be using from the Scanner class is:

The methods that we will be using from the Scanner class are:

We will now write a basic program to demonstrate how to use the Scanner
class to parse through a String for even numbers.

Output from this program:


Setting the Delimiter
When you create an instance of the Scanner class, the default
delimiter is whitespace. The Scanner class provides methods
to set the delimiter.

We will now write a program that demonstrates how to set the delimiter
of the Scanner class using the useDelimiter(String) method.

Output from this program:


Reading User Input
The constructor that we will be using from the Scanner class is:

The methods that we will be using from the Scanner class are:

We will now write a basic program to demonstrate how to read from
System.in using the Scanner class.

Output from this program:


Reading From a File
The constructor that we will be using from the Scanner class is:

The methods that we will be using from the Scanner class are:

We will now write a basic program to demonstrate how to read from a File
using the Scanner class.

test.txt:


Output from this program:

This message was edited 13 times. Last update was at 02/03/2008 07:08:29

[Email]
stdunbar

Newbie
[Avatar]

Joined: 06/22/2005 14:51:37
Messages: 903
Location: Superior, CO, USA
Offline

Nice article destin - great job!

Thanks for using the forums at hotjoe.com
[WWW] [Yahoo!] [ICQ]
 
Forum Index » How To Articles
Go to:   
Powered by JForum 2.1.9 © JForum Team
This site run by Scott Dunbar of Xigole Systems. © 2005-2012 - Scott Dunbar
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners
hotjoe.com, xigole.com, and Scott Dunbar have no affiliation with Oracle