Results 1 to 3 of 3
Thread: Some keywords
- 02-02-2011, 03:09 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 7
- Rep Power
- 0
Some keywords
Can any of you explain a bit these lines or just point out a tutorial.
/**
*Output:
28
*/
import java.util.Scanner;
public class MainClass {
public static void main(String args[]) {
String instr = "Name: Joe Age: 28 ID: 77";
Scanner conin = new Scanner(instr);
conin.findInLine("Age:"); // find Age
if (conin.hasNext())
System.out.println(conin.next());
else
System.out.println("Error!");
}
}
Scanner: findInLine(String str) : Scanner*«*java.util*«*Java by API
What's the "conin" variable? What's the funcition of the "new" with "Scanner"? And the "(instr)" ? the part "conin.findInLine" is to make that specific API uses the conin's stored information? I don't mind reading tutorials if you want to point out some.
- 02-02-2011, 03:19 AM #2
Scanner is a class in the Java API since ver 1.5. It is a convenience class that allows you to read input.
The new keyword you should have learnt in class. It is used anytime you want to create a new instance of a class.
Passing instr to the Scanner constructor simply means that the String value in the instr variable is what the Scanner object will read.
findInLine is a method of the Scanner class. Go to the Java API and read what it does.
- 02-03-2011, 12:21 AM #3
Member
- Join Date
- Feb 2011
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
Lucene - Keywords and Strings
By lucenenew in forum LuceneReplies: 0Last Post: 11-08-2009, 06:22 PM -
Demonstration of break and continue keywords
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:47 PM -
Reserved Keywords
By Java Tip in forum Java TipReplies: 1Last Post: 11-30-2007, 09:54 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks