Reference
Search Java methods, scan syntax and return types, read plain-English explanations, and run selected examples without leaving the reference flow.
Advertisement
Results
138 items match your filters.
toCharArray()
String Methods
Converts the string into a new character array.
length()
Returns the number of characters in the string.
substring()
Returns a substring beginning at the specified index and extending to the end or the specified end index.
indexOf()
Returns the index of the first occurrence of a character or substring.
charAt()
Returns the character at the specified index.
toLowerCase()
Returns a new string with all characters converted to lowercase.
toUpperCase()
Returns a new string with all characters converted to uppercase.
trim()
Returns a copy of the string with leading and trailing whitespace omitted.
replace()
Returns a new string resulting from replacing all occurrences of one character or substring with another.
split()
Splits the string into an array based on a regular expression.
startsWith()
Tests if the string starts with the specified prefix.
endsWith()
Tests if the string ends with the specified suffix.
contains()
Checks if the string contains the specified sequence of characters.
equals()
Compares this string to another string for equality.
concat()
Concatenates the specified string to the end of this string.
compareTo()
Compares two strings lexicographically.
compareToIgnoreCase()
Compares two strings lexicographically, ignoring case differences.
join()
Returns a new string composed of copies of the elements joined together with a specified delimiter.
format()
Returns a formatted string using the specified format string and arguments.
matches()
Tells whether this string matches the given regular expression.
repeat()
Returns a string whose value is the concatenation of this string repeated count times.
next()
Scanner Methods
Finds and returns the next complete token from this scanner as a string.
nextInt()
Scans the next token of the input as an int.
nextDouble()
Scans the next token of the input as a double.
nextLine()
Advances this scanner past the current line and returns the input that was skipped.
nextFloat()
Scans the next token of the input as a float.
hasNext()
Returns true if this scanner has another token in its input.
hasNextInt()
Returns true if the next token in the input can be interpreted as an int.
hasNextDouble()
Returns true if the next token in the input can be interpreted as a double.
close()
Closes this scanner.
File Declaration
File Methods
Create a File object representing a pathname.
createNewFile()
Creates a new, empty file if it does not already exist.
exists()
Tests whether the file or directory exists.
delete()
Deletes the file or directory denoted by this pathname.
isFile()
Tests whether the file is a normal file.
isDirectory()
Tests whether the file is a directory.
getName()
Returns the name of the file or directory.
getAbsolutePath()
Returns the absolute pathname string of this File object.
Returns the length of the file denoted by this pathname.
Try-Catch Block
Exception Handling
Catches and handles exceptions that may occur in a block of code.
Finally Block
A finally block always executes, regardless of whether an exception was thrown.
Multiple Catch Blocks
Handle different exception types separately by chaining catch blocks.
Throw Statement
Explicitly throw an exception from code.
Throws Keyword
Declares that a method can throw specified exceptions to the caller.
Common Exception Types
Frequently encountered exceptions such as NullPointerException, ArrayIndexOutOfBoundsException and ArithmeticException.
parseInt()
Number Methods
Parses the string argument as a signed integer.
parseDouble()
Parses the string argument as a double.
parseFloat()
Parses the string argument as a float.
valueOf()
Returns an instance of the wrapper class representing the specified value.
intValue()
Returns the value of this number as an int after a narrowing primitive conversion.
doubleValue()
Returns the value of this number as a double.
toString()
Returns a string representation of the specified argument.
Compares two numbers numerically.
max()
Math Methods
Returns the greater of two values.
min()
Returns the smaller of two values.
abs()
Returns the absolute value of a number.
sqrt()
Returns the positive square root of a double value.
pow()
Returns the value of the first argument raised to the power of the second argument.
round()
Returns the closest long or int to the argument.
floor()
Returns the largest double value that is less than or equal to the argument and is equal to a mathematical integer.
random()
Returns a double value greater than or equal to 0.0 and less than 1.0.
add()
ArrayList Methods
Appends a value to the tail of the list, expanding the backing array if necessary. Use this for the common “push” operation—amortized constant time with ArrayList and the return value lets you chain multiple adds or detect a rejected insert in constrained lists.
add(int index, E element)
Inserts an element at a specific index and shifts everything at and after that position one slot to the right. It’s perfect for maintaining sorted or priority-based lists, but be aware that inserting near the front costs O(n) because of the shift.
get()
Retrieves the element stored at a zero-based index without removing it. ArrayList provides O(1) random access, so get() is the fastest way to read items when you already know their position.
set()
Overwrites the element currently stored at the given index and returns the old value. Use set() when you want to update data in place—no shifting occurs, but the index must already exist.
remove()
Deletes the element at the provided index and shifts subsequent elements left to fill the gap. Removing from the end is cheap, while removing near the start is more expensive because every element must move one slot.
size()
Reports how many elements are currently stored, allowing you to guard index access or show counts in UI. Because the size is tracked internally, calling size() is constant time.
clear()
Removes every element and resets size to zero in one shot. References are nulled so the garbage collector can reclaim them, which makes clear() ideal when reusing a list between operations.
Scans the list to see whether any element equals the provided object using equals(). Helpful for quick membership checks or guarding against duplicates, though it performs a linear search.
Returns the first index whose element equals the searched value, or -1 when the item is missing. Use it to locate a selection before editing/removing it or to find duplicates.
put()
HashMap Methods
Adds or updates a key–value pair. If the key already exists, its value is replaced and the previous value is returned. put() is the standard write operation whenever you want the map to contain that key afterward.
putIfAbsent()
Writes a value only when the key is missing, returning the current mapping if one already exists. Ideal for initializing caches, computing defaults, or avoiding accidental overwrites.
Looks up the value for a key in O(1) average time. When the key is absent, null is returned, so combine this with containsKey() or supply a fallback to avoid NullPointerException.
Deletes a key–value pair and returns the value that was stored. Handy for eviction logic, tracking what was removed, or acknowledging a key existed before removal.
containsKey()
Checks whether a key is currently tracked without touching the stored value. This is a constant-time membership test to distinguish between “key mapped to null” and “key missing.”
containsValue()
Determines whether any entry stores the provided value by scanning the map. Because it’s a linear search, reserve it for diagnostics or rare checks.
Reports how many entries the map currently holds—useful for pagination, metrics, or quickly determining emptiness. This method runs in constant time.
Wipes the map by removing every key–value pair and resetting internal buckets. Use it when reusing a map object to avoid repeated allocations.
keySet()
Returns a live Set view over the keys so you can iterate, stream, or perform bulk operations without copying them. Mutations to the set reflect back to the map and vice versa.
Array Declaration
Array Operations
Different ways to declare and initialize arrays.
Access Elements
Access array elements by their index.
Looping Through Arrays
Use loops to iterate over array elements.
Sorting Arrays
Sort arrays using Arrays.sort().
Copying Arrays
Create a copy of an array using Arrays.copyOf().
Two-Dimensional Arrays
Declare and use multi-dimensional arrays.
Converting Arrays to Lists
Use Arrays.asList() to convert an array to a fixed-size list.
Arrays.fill()
Assigns the specified value to each element of the specified array.
For Loop
Loops
Repeats a block of code a fixed number of times.
While Loop
Repeats a block of code while a condition is true.
Do-While Loop
Executes a block of code once, then repeats it while a condition is true.
For-Each Loop
Iterates over elements of arrays or collections.
If Statement
Conditionals
Executes a block of code if a condition is true.
Else If Statement
Provides an additional condition to test if the previous if condition is false.
Switch Statement
Executes different code based on cases of an expression.
Ternary Operator
Shorthand for simple if–else statements.
List Interface
Collections
Represents an ordered, index-based sequence that can store duplicate elements. Lists are ideal when you need positional access (get, set) or frequent insertions/removals anywhere in the sequence. Implementations such as ArrayList and LinkedList trade off random access speed versus structural updates, so choose the one that matches your workload.
Set Interface
Models an unordered bag of unique elements—duplicates are automatically discarded. Sets are perfect for membership checks, ensuring uniqueness, and building lookup tables. HashSet offers constant-time contains/insert operations, while TreeSet keeps elements sorted and LinkedHashSet preserves insertion order.
Map Interface
Stores key–value pairs where each key maps to at most one value and lookups are done via get(key). Maps shine when you need fast association between identifiers and data—think caching, frequency counts, or configuration parameters. Common implementations include HashMap for constant-time operations and TreeMap for sorted key traversal.
Iterator
A lightweight cursor used to walk through a collection one element at a time without exposing its underlying structure. Iterators support hasNext()/next() to step forward and optional remove() to delete items safely during traversal, making them the preferred way to iterate over most collection types (especially when modifying during iteration).
Collections.sort()
Reorders a mutable List in-place using either natural ordering (Comparable) or a supplied Comparator. The method mutates the original list and runs in O(n log n) time, so it’s great for preparing data before binary search, displaying results alphabetically, or normalizing lists before equality checks.
isLetter()
Character Methods
Determines if the specified character is a letter.
isDigit()
Determines if the specified character is a digit.
isWhitespace()
Determines if the specified character is whitespace.
Converts the character argument to uppercase.
Converts the character argument to lowercase.
isUpperCase()
Determines if the specified character is an uppercase letter.
isLowerCase()
Determines if the specified character is a lowercase letter.
append()
StringBuilder Methods
Appends the specified string to this character sequence.
insert()
Inserts the string into this character sequence at the specified position.
Removes the characters in a substring of this sequence.
reverse()
Reverses the character sequence.
Converts this sequence to a String.
capacity()
Returns the current capacity of the StringBuilder.
ensureCapacity()
Ensures that the capacity is at least equal to the specified minimum.
Arrays.sort()
Arrays Class Methods
Sorts the specified array into ascending numerical order.
Arrays.binarySearch()
Searches the specified array for the specified value using the binary search algorithm.
Arrays.copyOf()
Copies the specified array, truncating or padding with zeros if necessary.
Arrays.toString()
Returns a string representation of the contents of the specified array.
Arrays.equals()
Returns true if the two specified arrays are equal to one another.
filter()
Stream Methods
Returns a stream consisting of the elements of this stream that match the given predicate.
map()
Returns a stream consisting of the results of applying the given function to the elements of this stream.
reduce()
Reduces the elements of this stream to a single value.
collect()
Performs a mutable reduction operation on the elements of this stream.
forEach()
Performs an action for each element of this stream.
sorted()
Returns a stream consisting of the elements of this stream, sorted according to natural order.
Collections Class Methods
Sorts the specified list into ascending order.
Collections.reverse()
Reverses the order of the elements in the specified list.
Collections.shuffle()
Randomly permutes the specified list using a default source of randomness.
Collections.binarySearch()
Searches the specified list for the specified object using the binary search algorithm.
Collections.unmodifiableList()
Returns an unmodifiable view of the specified list.
Collections.synchronizedList()
Returns a synchronized (thread–safe) list backed by the specified list.
main() Entry Point
Getting Started
Every Java application starts from a public static void main method. Keep it small while testing ideas.
System.out.println()
Console Output
Prints the provided value followed by a newline. Great for debugging or simple menus.
System.out.printf()
Formats and prints text using placeholders such as %s or %.2f.
Class Definition
OOP Essentials
Defines a blueprint for related state and behavior. Keep fields private and expose public methods.
Constructor Basics
Constructors run when objects are created. Use them to guarantee each instance starts valid.
Interface Declaration
Interfaces declare required methods without implementation. Classes can implement multiple interfaces.
Category
Best use
Use this entry when you need the syntax, return type, and a runnable example quickly.
Syntax
char[] toCharArray()
Returns
char[]
Example
String str = "Hello"; char[] chars = str.toCharArray(); for (char c : chars) { System.out.println(c); }
Live example
This runner wraps shorter snippets in a `Main` class automatically so you can test the example on the page.
Output
(run the example to see output here)