exam Flashcards
What is a return type in a method?
Example: int, double, String, boolean, etc. If the method does not return any value, the return type is void.
syntax of declaring a method:
public void methodName(parameters) { // method body }
.length method:
The .length method is used to get the length of arrays and strings in Java.
.substring() method:
The .substring() method is used to extract a substring from a string.
.toUpperCase() method:
The .toUpperCase() method is used to convert all characters in a string to uppercase.
.toLowerCase() method:
The .toLowerCase() method is used to convert all characters in a string to lowercase.
.equals() method:
The .equals() method is used to compare the contents of two strings.
.indexOf() method:
The .indexOf() method is used to find the index of a specified character or substring within a string.
How to create an ArrayList?
ArrayList<Type> listName = new ArrayList<Type>();</Type></Type>
Adding elements to an ArrayList:
Elements can be added to an ArrayList using the add() method:
Getting the size of an ArrayList:
the size() method:
Accessing elements in an ArrayList:
get() method and specifying the index:
Checking if an ArrayList contains an element:
using the contains() method:
Syntax of a for loop:
for (initialization; condition; update) {
Nested for loops:
You can have one or more for loops inside another for loop.
Useful for iterating over multi-dimensional arrays or performing repetitive tasks.
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++)