Additional Topics
In this section, we study:
ArrayList
ArrayList is a class in Java Collection Framework.Like array, it is a data structure containing a number of data elements.
All elements in an ArrayList have the same type.
Unlike array, ArrayList allows only object storage (generics).
ArrayList is dynamic data structure.
It can expand automatically when new objects are added and shrink automatically when objects are removed.
The index of ArrayList cell starts from 0.
We use methods to perform functions such as access, add, remove, and replace the elements in ArrayList.
In fact, ArrayList class has a number of methods to manipulate the ArrayList. Refer to Java API documentation.
void add(E obj)
E get(int index)
E remove(int index)
E set(int index, E obj)
E get(int index)
E remove(int index)
E set(int index, E obj)
ArrayListProcessing.java
Exception Handling
Exceptions are run time errors, such as dividing integer by 0, array index out of bounds, file not found, input mismatch, and etc.ExceptionProgram.java
Recursion
The method calls itself. It has two conceptual pieces:
Base case(s) – simplest case that the method knows how to solve.
A slightly smaller piece of the original problem.
A slightly smaller piece of the original problem.
FactorialWithRecursion.java