Java Basic
Java Home
Java, a widely-used programming language.
Java Introduction
Java, a renowned programming language originating in 1995, is under the ownership of Oracle.
Java Get Started
"Java Get Started": Dive into the fundamentals of Java programming, laying the groundwork for your coding exploration.
Java Syntax
Java syntax refers to the set of rules governing the structure and composition of Java code, including its keywords, punctuation, and conventions for writing statements and expressions.
Java Output / Print
Printing text refers to displaying textual information, such as words, sentences, or characters, typically on a screen or on paper.
Print Numbers refers to a command or function in programming that outputs a sequence of numerical values to a display or console.
Java Comments
Java comments are annotations within the code that are ignored by the compiler. They serve to enhance code readability and provide explanatory notes to developers.
Java Variables
Variables are named storage locations in programming that can hold and manipulate data values.
Print Variables refers to the act of outputting the values of variables to a display or console in a program.
Multiple Variables refers to the use of more than one variable in a program to store and manage different data values simultaneously.
Java identifiers are names used to identify variables, methods, classes, packages, and interfaces in Java code.
Real-life examples illustrate practical applications of concepts or principles in everyday situations.
Java Data Types
Data types are classifications that specify the type of data a variable can hold and the operations that can be performed on it.
Java Numbers refer to the various data types in Java used to represent numeric values, including integers, floating-point numbers, and characters.
Java Boolean Data Types represent values that are either true or false, used for logical operations and conditional statements.
Java characters represent single letters, digits, or special symbols enclosed within single quotes.
A real-life example of a String in Java is a person's name stored in a variable, such as "John Smith".
Non-primitive data types in Java are complex data structures that do not directly hold their data but rather reference memory locations where the data is stored.
Java Type Casting
Java type casting involves converting a variable of one data type into another data type. This can be either implicit or explicit and helps ensure compatibility between different data types during operations or assignments.
Java Operators
Java operators are symbols that perform operations on variables and values, such as arithmetic, logical, and relational operations.
Java Strings
Strings in Java are sequences of characters enclosed within double quotes. They are non-primitive data types that represent textual data and are extensively used for storing and manipulating textual information in Java programs.
Java String Concatenation refers to the process of combining or joining multiple strings into a single string. This can be achieved using the '+' operator or the concat() method in Java.
Numbers and strings are fundamental data types used for arithmetic operations and text manipulation, respectively.
Special characters are symbols with specific meanings in programming, used for tasks like formatting and control functions.
Java Math
Java Math is a class in the Java programming language that provides methods for performing basic numeric operations and mathematical functions.
Java Booleans
Java Booleans represent a data type that can have one of two values: true or false.
Java If ... Else
Java If ... Else statements provide a mechanism for executing different code blocks based on the evaluation of a boolean expression.
The else
statement in Java specifies a block of code to be executed if the condition in the if
statement is false.
The "else if" statement in Java allows you to specify additional conditions to be evaluated if the preceding "if" statement's condition is false.
Short Hand If...Else is a concise conditional statement used to execute a single line of code based on a condition, resembling a ternary operator.
Real-life examples demonstrate practical applications or instances of concepts in everyday situations.
Java Switch
The Java switch statement allows you to select one of many code blocks to be executed based on the value of a variable or expression.
Java While Loop
A while loop is a control flow statement that repeatedly executes a block of code as long as a specified condition is true.
The do/while loop in Java executes a block of code repeatedly until a specified condition becomes false, with the condition checked after each iteration.
Real-life examples provide tangible instances or illustrations of concepts in practical contexts.
Java For Loop
Remember to increment the variable utilized in the condition, or else the loop will continue indefinitely.
Nested loops in Java allow for the creation of loop structures within other loop structures, enabling iterative processes to be executed in multiple dimensions.
A "for each" loop is a programming construct that iterates over a collection of items, such as an array or a list, and performs a specific action for each item in the collection.
Real-life examples illustrate concepts through practical, everyday scenarios.
Java Break / Continue
In Java, the break
statement is used to exit a loop prematurely, immediately terminating the loop's execution. Conversely, the continue
statement is used to skip the current iteration of a loop and proceed to the next iteration.
Java Arrays
Java Arrays are containers that store multiple values of the same type in a single variable. They have a fixed size and allow elements to be accessed using an index.
Looping through an array involves iterating over each element in the array sequentially.
A real-life example illustrates a concept through a practical, everyday scenario.
Multidimensional arrays are arrays containing two or more dimensions, often used to store data in a grid or matrix format.
Java Methods
Java methods are blocks of code that perform a specific task and can be called upon to execute their functionality.
Parameters are variables that are passed into a function or method to influence its behavior or provide it with necessary data.
Return values are the values that a function or method sends back to the calling code to communicate its results or provide output.
Method overloading in Java allows you to define multiple methods with the same name but with different parameters.
Java scope refers to the visibility and accessibility of variables and methods within a program.
Java recursion involves a method calling itself to solve problems by breaking them down into smaller, similar subproblems.
Java Classes
A Java loop is a programming construct that repeatedly executes a block of code until a specified condition is met.
Class Fruit
|
objectsApple Banana Mango
|
Another example:
Class Car
|
objectsVolvo Audi Toyota
|
Therefore, a class serves as a blueprint for objects, while an object represents an instance of a class.
Upon creation, objects inherit all variables and methods from the class.
Further insights into classes and objects will be covered in the upcoming chapter.
Java classes define the structure and behavior of objects, while objects are instances of classes.
Java class attributes represent the data members or fields of a class that define its state.
Java class methods are functions defined within a class that operate on class attributes and perform specific tasks
Java constructors are special methods within a class used for initializing objects.
Java modifiers are keywords that provide additional information about classes, methods, variables, and other elements in a Java program, controlling their accessibility, behavior, and usage.
Java encapsulation: controlling access to an object's components to protect its internal state.
Java packages provide a way to organize and encapsulate a group of related classes and interfaces.
Java inheritance is a mechanism wherein a class (subclass) inherits properties and behaviors from another class (superclass), facilitating code reuse and hierarchical organization.
Java polymorphism enables objects of different classes to be treated as objects of a common superclass through method overriding.
Java inner classes are classes defined within other classes, providing a way to logically group classes and improve encapsulation and code organization.
Java abstraction is the process of hiding implementation details and showing only essential features of an object to the outside world.
A Java interface defines a contract for classes to implement, specifying a set of methods without providing their implementation details.
Java enums provide a way to define a fixed set of constants, ensuring type safety and clarity in code.
Java user output is the display of information generated by a Java program, typically through the console, graphical user interface (GUI), or other output streams.
Java Date and Time refer to the classes and APIs provided by Java for manipulating dates, times, and time zones in applications.
An ArrayList is a dynamically resizable implementation of the List interface in Java, allowing for flexible storage of elements in a sequential order.
A Java LinkedList is a linear data structure that consists of a sequence of elements where each element points to the next element in the sequence.
A Java HashMap is a data structure that stores key-value pairs, providing constant-time performance for basic operations like insertion, deletion, and retrieval, based on the hashCode of the keys.
A Java HashSet is a collection that stores unique elements, utilizing hashing to achieve constant-time performance for basic operations like add, remove, and contains.
A Java iterator is an object facilitating sequential traversal of collections, enabling access to elements and supporting operations like removal.
Java wrapper classes are objects that encapsulate primitive data types, providing utility methods and enabling them to be used in object-oriented contexts.
A Java exception is an event that disrupts the normal flow of a program's execution, typically due to errors or unexpected conditions, which must be handled to prevent program termination.
A regular expression (regex) is a series of characters defining a pattern for searching, utilized to match strings within text.
Java threads are the smallest units of execution within a Java program, allowing concurrent execution of tasks.
Java lambda expressions provide a concise way to represent anonymous functions, enabling the implementation of functional interfaces with a more compact syntax.
Java file Handling
Java files are text files containing source code written in the Java programming language, typically saved with a ".java" extension.
In Java, creating files involves using classes and methods from the java.io package to create, manipulate, and manage files within the file system.
In Java, reading files involves using classes and methods from the java.io package to access and extract data stored within files.
In Java, deleting files involves using methods from the java.io.File class to remove files from the file system.
Java How To
In Java, you can add numbers using arithmetic operators such as "+".
Counting words involves determining the number of individual words present within a text or document.
In Java, reversing a string involves rearranging the characters of a string in the opposite order.
In Java, finding the sum of array elements involves adding together all the values stored within the array.
To convert a string to an array in Java, use the split
method: String[] array = string.split("delimiter");
.
To sort an array in Java, use Arrays.sort(array);
.
Average is the sum of array elements divided by the number of elements.
To find the smallest element in an array in Java, utilize Arrays.stream(array).min().getAsInt();
.
To loop through an ArrayList in Java, use a for-each loop or an iterator.
To loop through a HashMap in Java, use a for-each loop or iterate over its key-value pairs using the entrySet() method.
To loop through an Enum in Java, use the values() method followed by a for-each loop.
In Java, you can calculate the area of a rectangle by multiplying its length by its width.
In Java, you can determine whether a number is even or odd by checking if it is divisible by 2 without a remainder.
Positive refers to something characterized by the presence or possession of favorable attributes, while negative denotes the absence or opposite of such attributes.
The square root of a number is the value which, when multiplied by itself, yields the original number.
A random number is a value selected from a set without any discernible pattern or predictability.
Java Reference
This section contains a Java reference documentation.
Java keywords are reserved words that have predefined meanings in the Java programming language and cannot be used as identifiers.
Assert is a programming statement used to validate assumptions or conditions within code, halting execution if the condition is false.
In Java, the "abstract" keyword is used to declare a class or method that must be subclassed or overridden, respectively, and cannot be instantiated on its own.
In Java, the "boolean" keyword is a primitive data type representing true or false values.
In Java, the "break" keyword is used to exit a loop or switch statement prematurely.
In Java, the "byte" keyword defines a primitive data type representing 8-bit signed integers.
In Java, the "case" keyword is used within switch statements to specify different branches of execution based on the value of an expression.
In Java, the "catch" keyword is used to handle exceptions in try-catch blocks by specifying code to execute when a particular exception occurs.
In Java, the "char" keyword denotes a primitive data type representing a single 16-bit Unicode character.
The "class" keyword in Java is used to declare a new class, which serves as a blueprint for creating objects with defined attributes and behaviors.
The "continue" keyword in Java is used to skip the rest of the current iteration of a loop and proceed to the next iteration.
In Java, the "default" keyword is used in switch statements to specify the block of code to be executed when none of the case expressions match the value of the switch expression.
In Java, the "do" keyword is used to start a do-while loop, which executes a block of code repeatedly until a specified condition becomes false, with the block of code executed at least once.
In Java, the "double" keyword is a data type used to declare variables that hold double-precision floating-point numbers.
In Java, the "else" keyword is used in conditional statements to execute a block of code when the preceding "if" condition evaluates to false.
In Java, the "enum" keyword is used to declare a special type that defines a set of constants.
Exports are goods or services produced in one country and sold to buyers in another country.
In Java, the "extends" keyword is used to indicate that a class is inheriting from another class, enabling the subclass to inherit fields and methods from the superclass.
The Java "final" keyword denotes that a variable, method, or class cannot be modified or extended, serving as a form of restriction or immutability.
The "finally" keyword in Java is used to define a block of code that is always executed, regardless of whether an exception is thrown or caught.
The "float" keyword in Java is used to declare single-precision 32-bit floating point variables.
The "for" keyword in Java initiates a loop structure for iterating over a range of values or collections.
The "if" keyword in Java is used to execute a block of code conditionally based on whether a specified condition evaluates to true.
The "implements" keyword in Java is used in class declarations to indicate that the class implements one or more interfaces.
The "import" The "import" keyword in Java is used to include classes or entire packages into a Java program, allowing access to their functionalities.
The "instanceof" keyword in Java is used to check whether an object is an instance of a particular class or interface.
The "int" keyword in Java is used to declare integer variables.
The "interface" keyword in Java is used to declare a reference type that only contains abstract method signatures, constants, and default methods.
The "long" keyword in Java is used to declare integer variables capable of storing larger whole numbers than the "int" data type, ranging from -9223372036854775808 to 9223372036854775807.
A module is a file containing Python code (definitions and statements) that can be imported and used in other Python programs.
The native
keyword in Java indicates that a method is implemented in platform-specific native code, typically using languages like C or C++.
The "new" keyword in Java is used to create new objects or instances of classes.
The "package" keyword in Java is used to declare a package, which is a grouping mechanism for organizing related classes and interfaces.
The "private" keyword in Java is used to restrict access to members (variables and methods) within the same class.
The "protected" keyword in Java is an access modifier used for class members (variables and methods) that allows access within the same package or by subclasses, regardless of package.
The "public" keyword in Java is an access modifier used to declare members (variables and methods) that can be accessed from any other class.
The "return" keyword in Java is used to exit a method and return a value to the caller.
The requires keyword in Java specifies dependencies on other modules within a module.
The "short" keyword in Java is used to declare integer variables capable of storing smaller whole numbers than the "int" data type, ranging from -32,768 to 32,767.
The "static" keyword in Java is used to declare members (variables and methods) that belong to the class itself, rather than to instances of the class.
The "super" keyword in Java is used to access members (variables and methods) of the superclass within a subclass, or to invoke the superclass constructor.
The "switch" keyword in Java is used to select one of many code blocks to be executed, based on the value of an expression.
The synchronized keyword in Java ensures that only one thread can access a block of code or method at a time, preventing concurrent modification or data corruption.
The "this" keyword in Java refers to the current object instance within a class, used to distinguish between instance variables and parameters with the same name.
The "throw" keyword in Java is used to explicitly throw an exception within a method or constructor.
The "throws" keyword in Java is used in method declarations to indicate that the method may throw one or more specified exceptions.
"Transient" typically refers to something temporary, fleeting, or not lasting for a long time.
The "try" keyword in Java is used to define a block of code within which exceptions may occur, and to catch and handle those exceptions.
"Var" is a keyword used to declare a variable with inferred type based on the assigned value.
The "void" keyword in Java is used to indicate that a method does not return any value.
The volatile keyword ensures that a variable's value is always read from and written to the main memory, providing visibility guarantees for changes made by one thread to be visible to others.
The "while" keyword in Java is used to create a loop that executes a block of code repeatedly as long as a specified condition evaluates to true.
Java String Methods
Java String Methods encompass a suite of built-in functions tailored for manipulating and querying strings in Java.
The Java String charAt() method retrieves the character at a specified index position within the string.
The codePointAt()
method in Java returns the Unicode code point at the specified index of a string.
The codePointBefore()
method in Java retrieves the Unicode code point value before the specified index in a string.
The codePointCount()
method in Java calculates the number of Unicode code points between two specified indices in a string.
The Java String compareTo()
method compares two strings lexicographically.
The Java String compareToIgnoreCase()
method compares two strings lexicographically, ignoring case differences, and returns an integer value indicating their relative order.
The Java String concat()
method appends one string to the end of another string.
The contains() method in Java checks if a specific sequence of characters exists within a string, returning true if found, and false otherwise.
The contentEquals() method in Java checks if the content of a string is equal to the content of another string, returning true if equal and false otherwise.
The Java String copyValueOf()
method creates a new String by copying the character array's values.
The Java endsWith()
method checks whether a string ends with a specified suffix and returns a boolean value indicating the result.
The Java equals()
method compares the content of two strings and returns true if they are equal, false otherwise.
The Java String equalsIgnoreCase()
method compares two strings while ignoring their case differences.
The Java String format()
method returns a formatted string using the specified format string and arguments.
The Java String getBytes()
method converts the string into a byte array.
The Java String getChars()
method copies characters from a string into an array of chars.
The Java String hashCode() method returns the hash code value for the string.
The Java String indexOf()
method returns the index of the first occurrence of a specified substring within the string.
The Java String isEmpty()
method checks if a string is empty, returning true if it contains no characters.
The Java String join()
method concatenates the elements of a given iterable with a delimiter.
The Java String lastIndexOf()
method finds the index of the last occurrence of a specified character or substring within the string.
The Java String length()
method returns the length of the string, i.e., the number of characters it contains.
The Java String matches()
method checks whether a string matches a given regular expression.
The Java String offsetByCodePoints()
method calculates the index of a character in the string by counting code points.
The Java String regionMatches()
method checks if a substring within a string matches another substring from another string, allowing for case-sensitive or case-insensitive comparison.
The Java String replace() method replaces all occurrences of a specified character or substring within the string with another character or substring.
The replaceAll()
method in Java replaces all occurrences of a specified substring with another substring within a string.
The Java String replaceFirst() method replaces the first occurrence of a specified substring with another substring.
The Java String split() method divides a string into an array of substrings based on a specified delimiter.
The Java String startsWith() method checks whether a string starts with a specified prefix.
The Java String subSequence() method returns a CharSequence representing a part of the original string, specified by the start and end indices.
The Java String substring() method extracts a portion of a string based on specified start and end indices, returning the resulting substring.
The Java String toCharArray() method converts a string into an array of characters.
The Java String toLowerCase() method converts all characters in a string to lowercase.
The toString()
method in Java converts an object into a string representation.
The toUpperCase()
method in Java converts all characters in a string to uppercase.
The trim()
method in Java removes leading and trailing whitespaces from a string. Here's its one-liner usage:
The valueOf()
method in Java converts different types of data into a string representation. Here's its one-liner usage:
Java Math Methods
The Java Math class offers a variety of methods for performing mathematical operations on numbers.
The Java Math `abs()` method returns the absolute value of a number.
The Java Math `acos()` method returns the arccosine of a value in radians.
The addExact()
method in Java's Math
class computes the sum of its arguments, throwing an ArithmeticException
if the result overflows an int
or long
data type.
The Java Math asin() method returns the arcsine of a value, in radians, within the range of -π/2 through π/2.
The Java Math atan() method returns the arctangent of a value, in radians, within the range of -π/2 through π/2.
The Java Math atan2() method returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta), in radians.
The Java Math cbrt() method returns the cube root of a double value.
The Java Math ceil() method returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer.
The Java Math copySign() method returns a value with the magnitude of the first argument and the sign of the second argument.
The Java Math cos() method returns the cosine of an angle in radians.
The Java Math cosh() method calculates the hyperbolic cosine of a value.
The Java Math decrementExact() method decrements a given value by one, throwing an exception if the result overflows.
The Java Math exp() method computes the exponential value of a given number.
The Java Math expm1() method computes for a given input .
The Java Math floor() method returns the largest integer less than or equal to a given number.
The Java Math floorDiv() method computes the largest integer quotient of dividing two numbers.
The Java Math floorMod() method computes the remainder of dividing two numbers with floor division.
The Java Math getExponent() method retrieves the exponent of a floating-point number in IEEE 754 format.
The Java Math hypot() method calculates the hypotenuse of a right triangle given its two perpendicular sides as arguments.
The Java Math IEEEremainder() method computes the remainder of division between two numbers following the IEEE 754 standard.
The Java Math incrementExact() method increments the given integer value by one, throwing an ArithmeticException if overflow occurs.
The Java Math log() method returns the natural logarithm (base e) of a double value.
The Java Math log10() method computes the base-10 logarithm of a double value.
The Java Math log1p() method computes the natural logarithm (base e) of the sum of the argument and 1.
The Java Math max() method returns the greater of two values, passed as arguments.
The Java Math min() method returns the smaller of two values, passed as arguments.
The Java Math multiplyExact() method calculates the product of two integers, throwing an ArithmeticException if the result overflows an integer.
The Java Math negateExact() method calculates the negation of an integer value, throwing an ArithmeticException if the result overflows the integer range.
The Java Math nextAfter()
method returns the floating-point number adjacent to a given value in the direction of another value.
The Java Math nextDown()
method returns the floating-point number adjacent to a given value in the direction of negative infinity.
The Java Math nextUp()
method returns the floating-point number adjacent to a given value in the direction of positive infinity.
The Java Math pow()
method calculates the value of a base raised to the power of an exponent.
The Java Math random()
method generates a random double value between 0.0 (inclusive) and 1.0 (exclusive).
The Java Math rint()
method returns the closest integer to a given floating-point value, rounding to the nearest whole number.
The java.lang.Math.round() is used round of the decimal numbers to the nearest value. This method is used to return the closest long to the argument, with ties rounding to positive infinity.
The Java Math scalb()
method scales a given value by a specified power of 2.
The Java Math signum()
method returns the signum function of the argument, indicating whether it's negative, positive, or zero.
The Java Math sin()
method calculates the sine of an angle given in radians.
The Java Math sinh()
method computes the hyperbolic sine of a given angle.
The Java Math sqrt()
method calculates the square root of a given number.
The Java Math subtractExact()
method computes the difference of two integers, throwing an exception if overflow occurs.
The tan() method returns the tangent of an angle.
The Java Math tanh()
method computes the hyperbolic tangent of a given angle.
The Java Math toDegrees()
method converts an angle measured in radians to degrees.
The Java Math toIntExact()
method converts a long value to an int, throwing an exception if the value overflows an int.
The Java Math toRadians()
method converts an angle measured in degrees to radians.
The Java Math ulp()
method returns the size of the smallest positive value that can be represented by the data type of the argument.
Java Output Methods
Java Output Methods refer to the various ways in which data can be displayed or printed to the console or other output streams in Java programs.
The Java Output print()
method writes text or values to the console without appending a newline character.
Display some formatted text on the console.
The Java Output println()
method writes text or values to the console, appending a newline character at the end.
Java Arrays Methods
The Java Arrays Class provides static methods to work with arrays, including sorting, searching, and filling arrays.
In the java.util package, the Arrays class offers methods for manipulating arrays.
The compare() method is used to compare two objects and return an integer indicating their order (negative if the first is less, zero if equal, positive if the first is greater).
The 'Arrays.equals()
' method in Java determines if two arrays are equal in content.
The 'Arrays.sort()
' method in Java arranges the elements of an array in ascending order.
The 'Arrays.fill()
' method in Java assigns a specified value to each element of an array.
The 'length
' property in Java arrays returns the number of elements in the array.
Java ArrayList Methods
Java ArrayList methods provide various functionalities to manipulate the elements, such as adding, removing, accessing, and iterating over elements.
The add() method appends an item to the end of the list.
The addAll() method adds all elements from a collection to the list.
The clear() method removes all elements from the list.
clone() is a method in Java that creates and returns a copy of an object.
contains() is a method in Java that checks whether a collection contains a specified element, returning true if found, false otherwise.
ensureCapacity() is a method in Java that increases the capacity of an ArrayList to ensure it can accommodate a specified number of elements without needing to resize the internal data array multiple times.
forEach()
is a method in Java that iterates over elements in a collection, applying a specified action to each element.
get() retrieves the element at a specified index from a list in Java.
indexOf() is a method in Java that returns the index of the first occurrence of a specified element in a list, or -1 if the element is not found.
isEmpty() is a method in Java that checks if a list is empty, returning true if it contains no elements, false otherwise.
iterator() is a method in Java that returns an iterator over the elements in a collection, allowing sequential traversal of the elements.
lastIndexOf() is a method in Java that returns the index of the last occurrence of a specified element in a list, or -1 if the element is not found.
listIterator() is a method in Java that returns a ListIterator for a list, allowing bidirectional traversal of the elements and modification of the list during iteration.
remove() is a method in Java that deletes the element currently being iterated over from a collection using an iterator, or removes the element at a specified index from a list.
removeAll() is a method in Java that removes all elements from a list that are also contained in a specified collection.
removeIf() is a method in Java that removes all elements from a list that satisfy a specified condition, as determined by a predicate.
replaceAll() is a method in Java that replaces all elements in a list with the result of applying a specified function to each element.
The retainAll() method in Java collections retains only the elements in the collection that are contained in the specified collection, removing all others.
A Set is a collection that contains no duplicate elements and has no guaranteed order.
The size() method returns the number of elements in the list.
The sort() method arranges the elements of a list in ascending order, according to their natural ordering.
The spliterator() method creates a Spliterator over the elements in the list.
subList() is a method in Java that returns a view of a portion of a list, specified by a range of indexes.
toArray() is a method in Java used to convert a collection or list into an array.
trimToSize() is a Java ArrayList method that trims the capacity of the list to its current size.
Java LinkedList Methods
Below is a table containing all LinkedList methods.
The add() method inserts an item into the list.
The addAll() method appends all items from a collection to the list.
The clear() method eradicates all items from the list.
The clone() method provides a duplicate of the LinkedList as an Object.
The contains() method returns true if an item is present in a list; otherwise, it returns false.
The forEach() method executes an action on each item within a list.
The get() method retrieves the item located at a specified position within the list.
The getFirst() method retrieves the first item in a list.
The getLast() method retrieves the last item in a list.
The indexOf() method retrieves the index of the first occurrence of a value in the list. If the item is not present in the list, it returns -1.
"isEmpty()" returns true if the list is empty; otherwise, it returns false.
"iterator()" returns an iterator over the elements in the list.
"lastIndexOf()" returns the index of the last occurrence of a specified element in the list, or -1 if it is not found.
"listIterator()" returns a ListIterator over the elements in the list.
"remove()" removes the current element from the list during iteration.
"removeAll()" removes all occurrences of specified elements from the list.
"removeFirst()" removes and returns the first element of the list.
"removeIf()" removes all elements from the list that satisfy the given predicate.
"removeLast()" removes and returns the last element of the list.
"replaceAll()" replaces each element in the list with the result of applying the specified operator.
"set()" updates the element at the specified index in the list with a new value.
size()" returns the number of elements in the list.
"sort()" arranges the elements of the list in ascending order according to their natural ordering, or using a specified comparator.
"spliterator()" creates a Spliterator over the elements in the list.
toArray()
is a method in Java used to convert a collection or a list into an array.
Java HashMap Methods
Java HashMap methods provide operations for storing, retrieving, and managing key-value pairs in a hash table.
The clear() method in HashMap removes all mappings from the map in a single operation.
The clone() method in HashMap creates and returns a shallow copy of the map instance.
In programming, compute() is a function used to perform calculations or process data based on given inputs and return the result.
computeIfAbsent() updates a map by computing and inserting a value for a key if the key is not already associated with a value.
computeIfPresent() updates a map by computing a new value for an existing entry if the entry's key is present and its current value is not null.
containsKey() checks if a map contains a specific key and returns true if found, false otherwise.
containsValue() checks if a map contains a specific value and returns true if found, false otherwise.
entrySet() returns a set view of the mappings contained in the map.
Each() isn't a standard method in programming, but if you're referring to its general usage, it typically represents iterating over each element/item in a collection, such as an array, list, or map.
get() retrieves the value associated with a specified key in a map.
getOrDefault() retrieves the value associated with a specified key in a map, or returns a default value if the key is not present.
isEmpty() checks if a map is empty and returns true if it contains no key-value mappings.
keySet() returns a set view of the keys contained in the map.
merge() combines values under a specified key in a map using a specified merging function.
put() inserts a new key-value pair into a map or updates the value for an existing key.
putAll()
copies all of the mappings from one map to another.
putIfAbsent() inserts a key-value pair into a map only if the key is not already present.
The remove() method in Python is used to delete the first occurrence of a specified element from a list.
The replace() method in Python is used to replace the occurrences of a specified value with another value in a string.
The replaceAll() method in Java is used to replace all occurrences of a specified value in a map with another value.
The size() function returns the number of elements in a collection, such as an array, list, or set.
The values() method returns a collection view of the values contained in a map.
Java Errors and Exception
Java Errors and Exceptions represent abnormal conditions or unexpected events that disrupt the normal flow of a program's execution.