Wrapper Methods: I Nteger and Long Wrapper Classes
Wrapper Methods: I Nteger and Long Wrapper Classes
Methods on Strings
char charAt(int index) Returns the character on the specified index
String concat(String str) Appends one string to another (just like “+”)
boolean equalsIgnoreCase(String str) determines the equality of two strings (ignoring the case)
int length() returns the number of characters of the string
String replace( char oldChar, replaces occurences of a character with a new character
char newChar)
String substring(int beginIndex, Returns a new string that is a substring of this string.
int endIndex)
String toLowerCase() Returns a string with uppercase characters converted
String toString() Returns the value of a string
String toUpperCase() Returns a string with lowercase characters converted
String trim() Removes whitespace from the ends of the string
String[] split(String regex) Splits this string around matches of the given regular
expression.Trailing empty strings are not included in the
resulting array.
java.io.OutputStreamWriter
OutputStreamWriter( Creates an OutputStreamWriter that uses the given charset
OutputStream out, CharsetEncoder enc) encoder.
Java io.class Key Constructor(s) Arguments Key Methods
File(File parent, String child) Creates a new File instance from a See below
parent abstract pathname and a Note read & write methods will throw
child pathname string. IOException, so needs to be caught.
File(String pathname) Creates a new File instance by
converting the given pathname string
into an abstract pathname.
File(String parent,String child) Creates a new File instance from a
parent pathname string and a child
pathname string.
FileWriter(File file)* Constructs a FileWriter object given
void close()
a File object. void flush()
FileWriter(String fileName)* Constructs a FileWriter object given
void write(int c)
* overloaded with apppend a file name. void write(String str, int off, int len)
option and throws IOException void write(char[], int off, int len)
BufferedWriter (Writer out) Creates a buffered character-output void close()
stream that uses a default-sized void flush()
output buffer. void newLine()
void write(/*as above*/)
PrintWriter(File file)~ Constructs without automatic line void close()
flushing, with the specified file. void flush()
PrintWriter(String fileName)~ Constructs without automatic line void write(/*as above*/)
flushing, with the specified file name. void write(char[] buf)
*PrintWriter(OutputStream out) Constructs without automatic line void write(String s)
flushing, from an existing format(String format, Object...args)
OutputStream. printf(String format, Object... args)
*PrintWriter(Writer out) Constructs without automatic line void print(primitive/Object)
flushing void println(primitive/Object)
*overloaded with boolean (~ throws FileNotFoundException, PrintWriter append(char c)
autoFlush. overloaded with String charset) PrintWriter append(CharSequence cs)
FileReader(File file) Creates a new FileReader, given the int read()
File to read from. int read(char[] cbuf, int off, int len)
FileReader(String fileName) Creates a new FileReader, given the void close()
name of the file to read from.
BufferedReader(Reader in) Creates a buffering character-input int read()
stream that uses a default-sized int read(char[] cbuf, int off, int len)
input buffer. String readLine()
java.io.File Description
public boolean createNewFile()* this method creates a new file if it doesn’t already exists
public boolean exists() checks if the file exists
public boolean delete() deletes a file or directory (if empty)
public boolean isDirectory() checks if the file is a directory
public boolean isFile() checks if the file is a file
public String[] list() lists the files in a directory, if the File is not a dir it returns null
public File[] listFiles() same as list expect returns a File[] instead of String[]
public boolean mkdir() creates a directory from the abstract pathname
public renameTo(File f) renames a file or directory (even if not empty)
public boolean mkdirs() creates directories including non existent parent dirs
*use in a try catch block with IOException
java.util.regex.Pattern
static Pattern compile(String regex) Compiles the given regular expression into a pattern.
static boolean matches(String regex, Compiles the given regular expression and attempts to match
CharSequence input) the given input against it.
Matcher matcher(CharSequence input) Creates a matcher that will match the given input against this
pattern
java.util.regex.Matcher
boolean find() Attempts to find the next subsequence of the input sequence that
matches the pattern.
String group() Returns the input subsequence matched by the previous match.
int start() Returns the start index of the previous match.
int end() Returns the offset after the last character matched.
java.lang.Comparable java.util.Comparator
int thisObject.compareTo(anotherObject) int compare(thisObject, anotherObject)
You must modify the class whose instances you You build a seperate class from the class whose
want to sort instances you want to sort
One sort sequence Many sort sequences (by creating many comparators)
Implemented frequently in the API by: String, Meant to be implemented to sort instances of third-party
Wrapper Classes, Date, Calendar... classes
Interface Map.Entry<K,V>
Key Interface methods Description
K getKey() Returns the key corresponding to this entry.
V getValue() Returns the value corresponding to this entry.
V setValue(V value) Replaces the value corresponding to this entry with
the specified value (optional operation).
Method Overview for NavigableMap
Key Interface Methods Description
NavigableMap<K,V> descendingMap() Returns a reverse order view of the mappings contained in this map
NavigableSet<K> descendingKeySet() Returns a reverse order NavigableSet view of the keys contained in
this map. The set is backed by the map.
NavigableSet<K> navigableKeySet() Returns a NavigableSet view of the keys contained in this map.
NavigableMap<K,V> headMap( Returns a view of the portion of this map whose keys are less than
K toKey, boolean inclusive) (or equal to, if inclusive is true) toKey
NavigableMap<K,V> tailMap( Returns a view of the portion of this map whose keys are greater
K fromKey, boolean inclusive) than (or equal to, if inclusive is true) fromKey
SortedMap<K,V> subMap( Returns a view of the portion of this map whose keys range from
K fromKey, K toKey) fromKey, inclusive, to toKey, exclusive.
NavigableMap<K,V> subMap( Returns a view of the portion of this map whose keys range from
K fromKey, boolean fromInclusive, fromKey to toKey.
K toKey, boolean toInclusive) The returned map is backed by this map, so changes in the
returned map are reflected in this map, and vice-versa.
firstEntry Map.Entry<K,V> firstEntry() Returns a key-value mapping associated with the least key in this
map, or null if the map is empty.
Map.Entry<K,V> pollFirstEntry() Removes and returns a key-value mapping associated with the
least key in this map, or null if the map is empty.
Map.Entry<K,V> lastEntry() Returns a key-value mapping associated with the greatest key in
this map, or null if the map is empty.
Map.Entry<K,V> pollLastEntry() Removes and returns a key-value mapping associated with the
greatest key in this map, or null if the map is empty.
K floorKey(K key) Returns the greatest key less than or equal to the given key, or null
if there is no such key.
K ceilingKey(K key) Returns the least key greater than or equal to the given key, or null
if there is no such key.
K higherKey(K key) Returns the least key strictly greater than the given key, or null if
there is no such key.
K lowerKey(K key) Returns the greatest key strictly less than the given key, or null if
there is no such key.
Map.Entry<K,V> floorEntry(K key) Returns a key-value mapping associated with the greatest key less
than or equal to the given key, or null if there is no such key.
Map.Entry<K,V> ceilingEntry(K key) Returns a key-value mapping associated with the least key greater
than or equal to the given key, or null if there is no such key.
Map.Entry<K,V> higherEntry(K key) Returns a key-value mapping associated with the least key strictly
greater than the given key, or null if there is no such key.
Map.Entry<K,V> lowerEntry(K key) Returns a key-value mapping associated with the greatest key
strictly less than the given key, or null if there is no such key.
java.lang.System class
Field Summary Description
static PrintStream err The "standard" error output stream.
static InputStream in The "standard" input stream
static PrintStream out The "standard" output stream.
Checked Exceptions
java.lang.Exception Description
ClassNotFoundException This signals that the JVM tried to load a class by its string name, but the
class could not be found. E.g. when the class name is misspelled while
starting program execution with the java command.
IllegalAccessException This is thrown when an application tries to reflectively create an instance,
set or get a field, or invoke a method, but the currently executing method
does not have access to the definition of the field, method or constructor.
InterruptedException Thrown when a thread is waiting, sleeping, or otherwise occupied, and the
thread is interrupted
ParseException Signals that an error has been reached unexpectedly while parsing.
CloneNotSupportedException Thrown to indicate that the clone method in class Object has been called
but that the object's class does not implement the Cloneable interface
IOException Signals that an I/O exception of some sort has occurred.
EOFException Signals that an end of file or end of stream has been reached unexpectedly
during input.
FileNotFoundException Signals that an attempt to open the file denoted by a specified pathname
has failed.
NotSerializableException Thrown when an instance is required to have a Serializable interface.
StreamCorruptedException Thrown when control information that was read from an object stream
violates internal consistency checks.
OptionalDataException Exception indicating the failure of an object read operation due to unread
primitive data, or the end of data belonging to a serialized object in the
stream
Unchecked Exceptions
java.lang.RuntimeException Description
ArithmeticException Thrown when an exceptional arithmetic condition has occurred. For
example, an integer "divide by zero" throws an instance of this class.
ArrayIndexOutOfBoundsException Thrown to indicate that an array has been accessed with an illegal
index. The index is either negative or greater than or equal to the size
of the array.
ClassCastException Thrown to indicate that the code has attempted to cast an object to a
subclass of which it is not an instance..
IllegalArgumentException Thrown to indicate that a method has been passed an illegal or
inappropriate argument
IllegalStateException Signals that a method has been invoked at an illegal or inappropriate
time.
IllegalMonitorStateException Thrown to indicate that a thread has attempted to wait on an object's
monitor or to notify other threads waiting on an object's monitor without
owning the specified monitor.
NoSuchElementException Thrown by the nextElement method of an Enumeration to indicate that
there are no more elements in the enumeration (iterator.next()).
NullPointerException This exception is typically thrown by the JVM when an attempt is made
to use the null value as a reference value to refer to an object.
NumberFormatException Thrown to indicate that the application has attempted to convert a
string to one of the numeric types, but that the string does not have the
appropriate format. The class NumberFormatException is a subclass
of the IllegalArgumentException class
Error
java.lang.Error Description
ExceptionInInitializerError An ExceptionInInitializerError is thrown to indicate that an exception
occurred during evaluation of a static initializer or the initializer for a
static variable.
StackOverflowError Thrown when a stack overflow occurs because an method recurses too
deeply.
NoClassDefFoundError JVM can’t find a .class file
AssertionError thrown when the statement’s boolean test returns false
java.lang.Runtime class
Method summary Description
static Runtime getRuntime() Returns the runtime object associated with the current Java
application.
void gc() Runs the garbage collector.