Вы находитесь на странице: 1из 11

Class: StringBuilder

Package: java.lang
Objects of this class are mutable
Return Type Name Description Type
StringBuilder() Constructor
StringBuilder(String str)
StringBuilder append(boolean b) Appends the string Method
append(char c) representation of the type of the
append(char [] str) passed argument.
append(double d)
append(int i)
append(float f)
append(long lng)
append(String str)
append(Object obj)
append(StringBuffer sb)
char charAt(int index) Returns the char in the sequence Method
at the specified index.
int length() Returns the length of the Method
sequence.
String substring(int start) Returns a new string from a Method
sequence starting from the
specified index till the end of
the sequence.
String substring(int start, int end) Returns a new string from a Method
sequence starting from the
specified start index and ends at
the specified end index.
int indexOf(String str) Returns the index of the first Method
occurrence of the string.
int indexOf(String str, int Returns the index of the first Method
fromIndex) occurrence of the string starting
search from the specified index.
int lastIndexOf(String str) Returns the last index of the Method
specified string.
int lastIndexOf(String str,int Returns the last index of the Method
fromIndex) specified string starting search
from the specified index.
StringBuilder insert(int offset, boolean b) Inserts the string of the second Method
insert(int offset, long lng) argument representation into the
insert(int offset, char c) sequqnce.
insert(int offset, char [] str)
insert(int offset, double d)

1
insert(int offset, float f)
insert(int offset, int i)
insert(int offset, Object obj)
insert(int offset, String b)

StringBuilder delete(int start, int end) Removes the character within Method
the sequence starting from start
index till the end index.
StringBuilder deleteCharAt(int index) Deletes the character at the Method
specified index position.
Examples String str = "Now is the time for all good men " + "to come to the aid of their
country.";

System.out.println(“indexOf(t)= ”+str.indexOf(‘t’));

System.out.println(“lastIndexOf(t)= ”+str.lastIndexOf(‘t’));

System.out.println(“indexOf(t,10)= ”+indexOf(‘t’,10));

System.out.println(“lastIndexOf(t,60)= ”+lastIndexOf(‘t’,60));

Output:

indexOf(t)= 7

"Now is the time for all good men " + "to come to the aid of their country.";

lastIndexOf(t)= 65

"Now is the time for all good men " + "to come to the aid of their country.";

indexOf(t,10)= 11

"Now is the time for all good men " + "to come to the aid of their country.";

lastIndexOf(t,60) = 55

"Now is the time for all good men " + "to come to the aid of their country.";

2
Class: File
Package: java.io
It's a class that concerned with file and directory manipulation.
Return Type Name Description Type
File(String filename) Creates a new file instance given Constructor
the file path name.
File(File parent,String child) Creates a new child file instance Constructor
from the specified parent file.
boolean canRead() Returns true if the file is allowed Method
for execution.
boolean canWrite() Returns true if the file is allowed Method
for writing.
boolean canExecute() Returns true if the file is allowed Method
for reading.
boolean exists() Returns true if the file exits. Method
boolean mkdir() Creates a new directory. Method
boolean isFile() Returns true if a specified file Method
denoted by the abstract pathname
is normal file.
boolean isDirectory() Returns true if a specified file Method
denoted by the abstract pathname
is normal directory.
boolean createNewFile() Creates an empty file named by
the abstract pathname if it doesn’t
exist.
String [] list() Returns an array of strings Method
containing the files and
directories names denoted by the
abstract pathname.
File [] listFiles() Returns an array of abstract Method
pathname denoting (referring to)
the files in the directory denoted
by this abstract pathname.
Long length() Gets the file size Method

3
Class: ObjectOutputStream
Package: java.io.OutputStream
Serializes (writes) object state to an Output Stream.
Return Name Description Type
Type
ObjectOutputStream() Creates an object output stream Constructor
ObjectOutputStream(OutputStream out) that writes to the specified output
ObjectOutputStream(FileOutputStream stream.
out)
void writeObject(Object obj) Writes the specified object to the Method
ObjectOutputStream

Class: ObjectInputStream
Package: java.io.InputStream
Deserializes a serialized object from an Input Stream.
Return Name Description Type
Type
ObjectInputStream() Creates an object intput stream Constructor
ObjectInputStream(InStream out) that reads from the specified
ObjectInputStream(FileInputStream out) input stream.
Object readObject() reads an object from the Method
ObjectInputStream

Class: Consol
Package: java.io
Provides for system input and output data streams, serialization and file system.
Return Type Name Description Type
Consol format(String fmt, Object…args) Writes the formatted string to the Method
printf(String format, Object…args) consol's output stream
String readLine() [Provides formatted prompt,] Method
readLine(String fmt,Object…args) reads a single line of text from
consol.
Char[] readPassword() [provides formatted prompt,] Method
readPassword(String fmt, Object… reads password from the consol
args) with echoingdisabled.

4
Class: PrintWriter
Package: java.io.Writer
This class prints formatted presentation of objects to text output stream.
Return Type Name Description Type
PrintWriter(File file) Creates a new printwriter for the Constructor
specified file (without automatic
flushing).
PrintWriter(OutputStream out) Creates a new printwriter for the Constructor
specified output stream (without
automatic flushing).
PrintWriter append(char c) Appends the specified character Method
append(CharSequence csn) or character sequences to this
writer.
void close() Closes the stream and releases Method
any system resources associated
to it.
void flush() Flushes the stream. Method
PrintWriter format(String format, Object…args) Writes a formatted string to the Method
printf(String format,Object…args) writer using the specified string
and args.

Class: NumberFormat
Package: java.text
Return Type Name Description Type
static getInstance() Returns the default number Method
final format for the current default
NumberFormat local.
static getInstance(Local loc) Returns the number format of Method
NumberFormat the specified local.
static getNumberInstance() Formats and parses the default Method
final numbers format in the default
NumberFormat local one.
static getNumberInstance(Local loc) Formats and parses the number Method
NumberFormat format in the specified local
one.
static getCurrencyInstance() Returns the currency format in Method
final the default local one.
NumberFormat

5
static getCurrencyInstance(Local loc) Returns the currency format in Method
NumberFormat the specified local one.
static getIntegerInstance() Formats and parses the number Method
final integer format of the default
NumberFormat local. Floating point numbers
are rounded.
static getIntegerInstance(Local loc) Returns the integer numbers in Method
NumberFormat the specified local format.
static getPercentInstance() Formats and parses the Method
final percentages in the default local
NumberFormat one.
static getPercentInstance(Local loc) Returns a percentage format of Method
NumberFormat the specified local.
final format(long number) Returns number into string Method
String format(double number) format
number parse(String s) -Parses a string into number. Method
- Throws ParseException.
-parses the beginning of string
and stops till it reaches to a
character.
- it’s also used for parsing
currency
Examples on NumberFormat nf = new NumberFormat.getInstance();
parse String one = “456abs”;
String two = “-2.5165e10”;
String one = “x85.3”;
System.out.println(nf.parse(one)); === 456
System.out.println(nf.parse(two)); === -2.165
System.out.println(nf.parse(three)); === throws ParseException

6
Class: NumberFormat
- Subclass of NumberFormat class
Adds more features for formatting floating point number, specifying precisions, leading and trailing
zeros, and prefixes and suffixes.
DecimalFormat can be obtained in 2 ways:
1-Inistantiate a new DecimalFormat from one of its constructors, which is useful when using
default local.
2-Using getInstance() method and cast the return type to DecimalFormat, this’s useful when using
speicified local settings.
Symbol Location Localized? Meaning
0 Number Yes Digit
# Number Yes Digit, zero shows as absent
. Number Yes Decimal separator or monetary decimal separator
- Number Yes Minus sign
, Number Yes Grouping separator
E Number Yes Separates mantissa and exponent in scientific notation. Need
not be quoted in prefix or suffix.
; Subpattern Yes Separates positive and negative subpatterns
boundary
% Prefix or Yes Multiply by 100 and show as percentage
suffix
\u2030 Prefix or Yes Multiply by 1000 and show as per mille
suffix
¤ (\u00A4) Prefix or No Currency sign, replaced by currency symbol. If doubled,
suffix replaced by international currency symbol. If present in a
pattern, the monetary decimal separator is used instead of the
decimal separator.
' Prefix or No Used to quote special characters in a prefix or suffix, for
suffix example, "'#'#" formats 123 to "#123". To create a single quote
itself, use two in a row: "# o''clock".
Examples double d = 1234567.437
DecimalForamt one = new DeciamlFormat(“###,###,###”);
DecimalForamt two = new DeciamlFormat(“000,000,000.00000”);
DecimalForamt three = new DeciamlFormat(“$#,###,###.##”);

Output of the following:


One: 1,234,567.437
two: 001,234,567.43700
three: $1,234,567.44

Class: DateFormat

7
Package: java.text
It's an abstract class that formates and parses dates and times for a specific local.
Return Type Name Description Type
static getDateInstance() Returns dates in formate of the Method
final default local.
DateFormat
static getDateInstance(int style,Local loc) -Returns date in style and format Method
final of the specified local.
DateFormate -Available formatting style:
FULL,LONG,MEDIUM,SHORT

static getTimeInstance() Returns time in default local Method


final format
DateFormat
static getTimeInstance(int style,Local loc) -Returns time in format and style Method
final of the specified local.
DateFormat -Available formatting style:
FULL,LONG,MEDIUM,SHORT
static geetDatTimeInstance() Returns date and time in format Method
final of local default.
DateFormat
static getDateTimeInstance(int style,Local -Returns date and time in format Method
final loc) and style of the specified local.
DateFormat -Available formatting style:
FULL,LONG,MEDIUM,SHORT
final format(Date date) Represents time in milliseconds Method
String
Date parse(String source) Returns string into date format Method

8
Class: Scanner
Package: java.util
It's a text scanner that parses primitive types and strings into tokens. (token is a group of
characters).
Delimiters for tokens are whitespace or a regular expression.
Return Type Name Description Type
public Scanner(File source) throws Constructor
FileNotFound
public Scanner(InputStream source) Constructor
public Scanner(String source) Constructor
boolean hasNext() Returns true if there's another Method
token in the scanner input
boolean hasNext(Pattern pattern) Returns true if the next complete Method
token matches the specified
pattern
boolean hasNext(String pattern) Returns true if the next token Method
matches the pattern constructed
from the specified string.
String next() Finds and returns the next Method
complete token from this scanner
String next(Pattern pattern) Returns the next token if it Method
matches the specified pattern
String next(String pattern) Returns the next token if it Method
matches the pattern constructed
from the specified string
Scanner useDelimiter(Pattern pattern) Sets the scanner's delimiter to the Method
specified pattern
Scanner useDelimiter(String pattern) Sets the scanner's delimiter to the Method
pattern constructed from the
specified string

9
Package: java.util.regex

Class: Pattern
Pattern object is a compiled representation of the regular expression. It has no public constructor and it's a final
class
Return Type Name Description Type
static compile(String regex) Compile the given regular Method
pattern expression into pattern
Matcher Matcher(CharSequence input) Creates a matcher that will match Method
the given input against the pattern
static matches(String regex, -Compiles the given regex. Method
boolean CharSequence input) -matches the compiles regex
against the given input .
String pattern() Returns the regex in which the Method
pattern was compiled
String[] split(CharSequence input) Splits the given input sequence Method
from the pattern.
String[] split(CharSequence input, int limit) Splits the given input sequence Method
from the pattern "limit" times.
Class: Matcher
An engine that performs match operation on the character sequence by interpreting a pattern.
Return Type Name Description Type
int end() Returns the index of the last Method
matched character, plus one.
int first() Returns the index of the first Method
character matched, plus one.
Metacharacters of Regular Expressions
Metacharacter Description
. Any character
* Match the preceding character any number of times
+ Match the previous character one or more times
? Match the previous character 0 or one time
\d Digit 0-9
\s Whitespace character

10
\w Word character (letters, numbers and underscore)
[] Match anything inside the brackets for one character position once
() Use parentheses for grouping together search expressions

11

Вам также может понравиться