hashCode(): =========== ==> it is an Object class method. ==> hashCode is an integer value. Syntax: Object-name.hashCode(); Object-name ==> address ==> converted into an integer Q: WHEN WE CAN SAY THE OBJECTS ARE EQUAL? Ans: when object with same content then, we can say those objects are equal. class A{ A(int x,int y){ this.x = x; this.y = y; } } public class Main{ public static void main(String[] args) { A aobj = new A(100,200); A bobj = new A(100,200); aobj.equals(bobj); ==> false } } Q: ARE EQUAL OBJECTS WITH SAME HASHCODE? Ans: Yes package package1; import java.util.Objects; class ClassA{ private int x; public ClassA(int x) { this.x = x; } @Override public int hashCode() { return Objects.hash(x); } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; ClassA other = (ClassA) obj; return x == other.x; } } public class MainClass { public static void main(String[] args) { ClassA a1 = new ClassA(10); ClassA a2 = new ClassA(10); System.out.println(a1.equals(a2)); System.out.println(a1.hashCode()); System.out.println(a2.hashCode()); } } ========================================================== toString(): =========== ==> an Object class method. ==> if the toString() not overridden: ===================================== Output: package.subPackage.class_name@unsignedhexaNumber package package1; class ClassB{ private int x; public ClassB() { this.x = 100; } } public class Main { public static void main(String[] args) { ClassB cb = new ClassB(); System.out.println(cb.toString()); } } Output: ======= package1.ClassB@49097b5d ==> If the toString() overridden: ================================== package package1; class ClassB{ private int x; public ClassB() { this.x = 100; } @Override public String toString() { return "ClassB [x=" + x + "]"; } } public class Main { public static void main(String[] args) { ClassB cb = new ClassB(); System.out.println(cb.toString()); } } Output: ======= ClassB [x=100] ================================================== ArrayList ========= -> ArrayList is a class which implements from List Interface. Syntax: public class ArrayList implements List{ } -> ArrayList is the collection elements elements are objects. -> The Object of ArrayList class can be defined in two ways: 1) Normal Object Creation ==> Can be for storing the homogeneous elements. 2) Generic Object Creation ==> Can be for storing the heterogeneous elements. 1) Normal Object Creation ========================== Syntax: ClassName object-name = new ClassName(); ArrayList lst = new ArrayList(); 2) Generic Object Creation =========================== Syntax: ArrayList ObjectName = new ArrayList(); Ex: ArrayList lst = new ArrayList(); Note: ===== While creating an Object for ArrayList, the Object Type in <> is mandatory in left side of '=' but it is optional in right side of '='. Ex: ArrayList employees = new ArrayList<>(); -> While creating an object for ArrayList class, the JVM can reserve the capacity for that object with 10 elements. (default capacity). ("ArrayList can be an array with 10 elements by default). Note: ==== Array cannot be dynamic in size. but, the ArrayList can be dynamic in size. we can increase or decrease the size of the ArrayList object. -> if we want to add the 11th element to the given ArrayList Object: Default_Capacity_Array_List + 50% of Defailt_Capacity Default Capacity ==> 10 50% of Default Capacity ==> 5 ==> Resizable Capacity ==> 10 + 5 = 15 -> If we want to add 16th element, then: Original_Capacity: 15 50% of Original_Capacity = 15/2 ==> 7 ==> the ArrayList after the resize ==> 15 + 7 ==> 22 package io.arraylist; import java.util.ArrayList; public class MainClass { public static void main(String[] args) { ArrayList lst1 = new ArrayList(); // Normal Object creation for ArrayList ArrayList lst2 = new ArrayList(); // Generic form of ArralyList Object // adding of Elements // add() can add the element at the end of the ArrayList object by default. // add() can do appending lst1.add(100); lst1.add(200); lst1.add(300); System.out.println("The ArrayList Object After the appending:"+lst1); // System.out.println("The Capacity of object = "+lst1.ensureCapacity()); System.out.println("The Size of the lst1 = "+lst1.size()); // Inserting of data into arrayList lst2.add(1000); lst2.add(2000); lst2.add(300); System.out.println("Lst2 before Insertion = "+lst2); // add(position,value) lst2.add(2,4000); System.out.println("lst2 after the Insertion = "+lst2); lst1.remove(1); System.out.println("lst1 = "+lst1); } }