Java Reference
In-Depth Information
Useful Methods of Scanner Objects
Method
Description
Reads and returns the next token as a String
next()
Reads and returns a double value
nextDouble()
Reads and returns an int value
nextInt()
Reads and returns the next line of input as a String
nextLine()
Returns true if there is another token to be read
hasNext()
Returns true if there is another token to be read and if it can be
interpreted as a double
hasNextDouble()
Returns true if there is another token to be read and if it can be
interpreted as an int
hasNextInt()
Returns true if there is another line of input to be read
hasNextLine()
Useful Methods of String Objects
Method
Description
Example (assuming s is "hello" )
Returns character at a specific
s.charAt(1) returns 'e'
charAt(index)
index
Tests whether the string ends
s.endsWith("llo") returns
endsWith(text)
with some text
true
Returns index of a particular
s.indexOf("o") returns 4
indexOf(text)
character or String ( -1
if not present)
Returns number of characters
s.length() returns 5
length()
in the string
Tests whether the string starts
s.startsWith("hi") returns
startsWith(text)
with some text
false
substring(start, Returns characters from start
s.substring(1, 3)
index to just before stop index
returns "el"
stop)
Returns a new string with all
s.toLowerCase() returns
toLowerCase()
lowercase letters
"hello"
Returns a new string with all
s.toUpperCase() returns
toUpperCase()
uppercase letters
"HELLO"
 
 
Search WWH ::




Custom Search