// 1. Reverse an ArrayList without using inbuilt method
// 2. Find Duplicate Elements in a List
// 3. Alphabetical Order and Ascending Order (Done in ArrayList)
// 4. Merge Two Lists and Remove Duplicates
// 5. Removing Even Nos from the List
// 6. Array to List, List to Array
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
public class CollectionsInJava {
public static void main(String[] args) {
// 1. Reverse an ArrayList without using inbuilt method
// 2. Find Duplicate Elements in a List
// 3. Alphabetical Order and Ascending Order (Done in ArrayList)
// 4. Merge Two Lists and Remove Duplicates
// 5. Removing Even Nos from the List
// 6. Array to List, List to Array
ArrayList<String> names = new ArrayList<>(Arrays.asList("Abinaya", "Ramya", "Gowri", "Swetha", "Sugi", "Anusuya", "Moogambigai","Jasima","Aysha"));
ArrayList<Integer> al2 = new ArrayList<>(Arrays.asList(100,90,30,20,60,40));
ArrayList<Integer> al = insertValuesIntoAL();
System.out.println("Before Reversing ArrayList="+ al);
System.out.println("Reversed ArrayList="+ reverseArrayList(al));
System.out.println("Duplicates in ArrayList="+findDuplicates(al));
System.out.println("Before Order = "+names);
Collections.sort(names);
System.out.println("After Alphabetical Order = " + names);
Collections.sort(al);
System.out.println("Ascending Order = "+ al);
System.out.println("List -1 = "+al);
System.out.println("List -2 = "+al2);
System.out.println("After Merging and Removing Duplicates="+mergeTwoLists(al,al2));
System.out.println("After Removing Even Nos fromt the List-1 = "+removeEvenNos(al));
arrayToListViceVersa(al,new int[] {11,12,13,14,15}); //Sending ArrayList and anonymous array
}
// 1. Reverse an ArrayList without using inbuilt method
private static ArrayList<Integer> reverseArrayList(ArrayList<Integer> al) {
int n=al.size();
int j=n-1, mid=n/2;
for (int i=0; i<mid; i++) {
int temp = al.get(i);
al.set(i, al.get(j));
al.set(j--, temp);
}
return al;
}
// 2. Find Duplicate Elements in a List
private static ArrayList<Integer> findDuplicates(ArrayList<Integer> al) {
HashSet<Integer> hs = new HashSet<>();
ArrayList<Integer> arl = new ArrayList<>();
for (int ele:al) {
if (!hs.add(ele)) arl.add(ele);
}
return arl;
}
//4. Merge Two Lists into one and Remove Duplicates
private static HashSet<Integer> mergeTwoLists(ArrayList<Integer> arl1,ArrayList<Integer> arl2) {
ArrayList<Integer> resAl = new ArrayList<>();
HashSet<Integer> hs = new HashSet<>();
hs.addAll(arl1);
hs.addAll(arl2);
return hs;
}
// 5. Removing Even Nos from the List
private static ArrayList<Integer> removeEvenNos(ArrayList<Integer> al) {
ArrayList<Integer> res = new ArrayList<>();
Iterator itr = al.iterator();
while (itr.hasNext()) {
int ele = (int)itr.next();
if (ele%2==1) res.add(ele);
}
return res;
}
// 6. Array to List, List to Array
private static void arrayToListViceVersa(ArrayList<Integer> arl, int[] ar) {
Integer arr[] = arl.toArray(new Integer[0]);
System.out.println("Convert List to Array = " + Arrays.toString(arr));
List<Integer> lst = Arrays.asList(arr);
System.out.println("Convert Array to List = " + lst);
}
private static ArrayList<Integer> insertValuesIntoAL() {
Integer[] ar = {30,40,60,10,94,23,05,46, 40, 94};
ArrayList<Integer> arl = new ArrayList<>();
Collections.addAll(arl, ar);
//Collections.reverse(al); //IN BUILT METHOD
return arl;
//Arrays.sort(ar);
//List lst = Arrays.asList(ar); //TBD
//return new ArrayList<Integer>(lst);
}
}
An Exception is an unexpected or unwanted event which occurs during the execution of a program that typically disrupts the normal flow of execution.
This is definition OK but what I understand : The programβs execution is getting stopped abnormally when it reaches some point which have some mistake/error β it may be small or big, compilation or runtime or logical mistake. And its not proceeding with further statements. Handling this situation is called exception handling. Cool. Isnβt it?
Why Exception Handling?
If we do not handle the exception program execution will stop. To make the program run smoothly and avoid stopping due to minor issues/exceptions, we should handle it.
So, how it is represented, In Java everything is class, right? The derived classes of java.lang.Throwable are Error and Exception. For better understanding lets have a look at the hierarchical structure.
Here I could see Exception and Error β when we hear these words looks similar right. So What could be the difference?
Errors are some serious issues which is beyond our control like System oriented errors. Ex. StackOverFlowError, OutOfMemoryError (Lets discuss this later).
Exception is a situation which we can handle,
through try-catch-(finally) block of code
Throws keyword in method signature.
try-catch-Finally :
What is the meaning? As we are the owner of our code, we do have some idea about the possible problems or exceptions which we can solve or handle through this try-catch block of code.
For Ex. Task : Make a Tasty Dish.
What could be the exceptions?
Some spice added in lower quantity.
Chosen vessel may be smaller in size
some additional stuff may not be available
To overcome these exception we can use try-catch block.
Here there could be more catches for one try as one task may encounter many different issues. If it is solvable its called exception and we try to catch in catch blocks. The JVM process our code (cookingProcess) and if it encounter one problem like QtyException_Spice, it will throw the appropriate object. Then it will be caught by the corresponding catch, which will execute add_Little_More_Spice() and prevent the code from failing.
Here we see one more word, Exception, which is the parent class of all exceptions. Sometimes we may encounter the issue that is not listed (perhaps forgotten) but its solvable. In such cases, we can use the parent class object (since a parent class object can act as a child object) to catch any exception that is not listed.
Fine, all good. But what is the purpose of Finally here? Finally is the block of code that will always be executed, no matter if exception occurs or not. It doesnβt matter if you made a good dish or a bad one, but the kitchen must be cleaned. The same applies here: the finally block is used for releasing system resources that were mainly used (Ex. File). However, we can also write our own code in the finally block based on the specific requirements.
We have a situation where you have one cylinder to cook, and it gets emptied during cooking, so we cannot proceed. This will fail our process TastyDish, this situation cannot be handled immediately. This is called Error. Now lets recall the definition βErrors are serious issues that are beyond our control like a system crash or resource limitations.β Now we could understand, right?
Ex. OutOfMemoryError β when we load too much data, JVM runs out of memory. StackOverFlowError β when an infinite loop or recursion without base condition will make the stack overflow.
Lets revisit exceptions β they can be classified into two categories:
Checked Exception
UnChecked Exception.
What is Checked Exceptions?
Checked Exception is the exception which occurs at compile time. It will not allow you to run the code if you are not handling through try-catch or declares throws method.
Lets get into deeper for the clear understanding, the compiler predicts/doubts the part of our code which may throw the exceptions/mistakes which lead to stopping the execution. So that it will not allow you to run, it is forcing you to catch the exception through the above one of mechanisms.
If it is not clear, let us take an example, in the above code we have VesselException and QtyException_Spice . You are at your initial stage of cooking under the supervision of your parent. So we are ordered/ instructed to keep the big vessel and the spices nearby in case you may need it when the problem arise. If you are not keeping it nearby parent is not allowing you to start cooking (initial time ). Parent is compiler here.
throws:
So Expected exception by the compiler is called Checked Exception, and the compiler force us to handle. One solution we know try-catch-finally, what is that through declaration in the method? The exception in which method can be expected, that method should use the keyword βthrows <ExceptionClassName-1>β that is, it specifies this method may lead to the exceptions from the list of classes specified after throws keyword. After throws can be one class or more than one. whoever using this method with this declaration in method signature will aware of that and may handle it.
The good example for this is, IOException (parent) β FileNotFoundException (child). If you are trying to open a file, read it, the possible exceptions are: File Path Incorrect, File doesnβt exist, File Permission, Network issues etc. For Ex.
public static void main(String[] args) {
try {
// Calling the method that may throw a FileNotFoundException
readFile("nonexistentfile.txt");
} catch (FileNotFoundException e) {
// Handle exception here
System.out.println("File not found! Please check the file path.");
e.printStackTrace();
}
}
// Method that throws FileNotFoundException
public static void readFile(String fileName) throws FileNotFoundException {
File file = new File(fileName);
Scanner scanner = new Scanner(file); // This line may throw FileNotFoundException
while (scanner.hasNextLine()) {
System.out.println(scanner.nextLine());
}
scanner.close();
}
What is Unchecked Exception?
The compiler will not alert you about this exception, instead you will experience at runtime only. This not required to be declared or caught, but handling is advisable. These are all subclasses of RunTimeException (Error also will throw runtime exception only). It could be thrown when runtime issues, illegal arguments, or programming issues.
Ex.Invalid index in an array, or trying to take value from a null object, or dividing by zero.
int[] arr = new int[3]; System.out.println(arr[5]); /* Throws ArrayIndexOutOfBoundsException */
What is throw?
Instead JRE throws error, the developer can throw the exception object (Predefined or UserDefined) to signal some erroneous situation and wants to stop the execution. For ex, you have the idea of wrong input and wants to give your own error message.
public class SampleOfThrow {
public static void main(String[] args) {
// a/b --> b should not be 0
Scanner scn = new Scanner(System.in);
int a = scn.nextInt();
int b = scn.nextInt();
if (b==0) throw new ArithmeticException("b value could not be zero");
System.out.print(a/b);
}
}
Hey, wait, I read the word, User Defined Exception above. which means the developer (we) also can create our own exception and can throw it. Yes, absolutely. How? In Java everything is class, right? So through class only, but on one condition it should extend the parent Exception class in order to specify it is an exception.
//User Defined Exception
class UsDef extends Exception {
public UsDef(String message) {
super(message); //will call Exception class // and send the own error message
}
}
public class MainClass {
public static void main(String[] args) {
try {
Scanner scn = new Scanner(System.in);
boolean moreSalt = scn.nextBoolean();
validateFood(moreSalt);
// This method will throw an TooMuchSaltException
} catch (TooMuchSaltException e) {
System.out.println(e.getMessage()); // Catching and handling the custom exception
}
}
// Method that throws TooMuchSaltException if food contains too much salt and can't eat
public static void validateFood(boolean moreSalt) throws TooMuchSaltException {
if (moreSalt) {
throw new TooMuchSaltException("Food is too salty.");
}
System.out.println("Salt is in correct quantity");
}
}
Now Lets have a look at some important Exception Handling points in java of view. (The following are taken from chatGPT)
Error Vs. Exception
Aspect
Error
Exception
Definition
An Error represents a serious problem that a Java application cannot reasonably recover from. These are usually related to the Java runtime environment or the system.
An Exception represents conditions that can be handled or recovered from during the applicationβs execution, usually due to issues in the programβs logic or input.
Superclass
java.lang.Error
java.lang.Exception
Recovery
Errors usually cannot be recovered from, and it is generally not advisable to catch them.
Exceptions can typically be caught and handled by the program to allow for recovery or graceful failure.
I am going to explain about how to create servlet and Deploy on Apache Tomcat Server 10.1 manually in any Linux distributions.
Directory Structure should be represented asΒ below
You can keep βaaavvvβ folder as any name youΒ want.
How to create Servlet on Apache Tomcat 10 inΒ Linux
Step:1
Create a folder in /usr/share/tomcat10/webapps folderΒ , In that folder create any folder name as you like, I create βmyappsβ folder name asΒ example.
cd /usr/share/tomcat10/webapps/;sudo mkdirΒ myapps
Step:2
Go into myappsΒ , then create βWEB-INFβ directory
cd myapps;sudo mkdirΒ WEB-INF
Step:3
Go into WEB-INF, then create βclassesβ directory
cd WEB-INF;sudo mkdirΒ classes
Step:4
Go into classes directory, and create java file named βTeamTesters.javaβ for this example, you can create any name youΒ want.
package taskPkg;
import java.util.Scanner;
public class SubArray {
public static void main(String[] args) {
// FINDING SUBARRAY AND ITS POSITION
System.out.println("Enter a sentence to search in.");
Scanner scn = new Scanner(System.in);
String sentn = scn.nextLine();
System.out.println("Enter a word to be searched.");
String word = scn.next();
scn.close();
char[] sentence = sentn.toCharArray();
char[] key = word.toCharArray();
int n = sentence.length, m = key.length;
int i = 0, j = 0, st = 0; // i- maintain index in the sentence, j-maintain index in key
boolean match = false;
while (i < n && j < m) {//
//System.out.println("i=" + i + " sentence[i]=" + sentence[i] + " j=" + j + " key[j]=" + key[j]);
if (sentence[i] == key[j]) { //if it matches incrementing both pos
i++;
j++;
if (j == m) { //if the key reaches end, made the match and exit
match = true;
break;
}
}
else { // if no match move on to the next letter, but key should start from 0
j = 0;
i=st+1;
st = i; // this is to save the starting of the subarray
}
}
if (match)
System.out.println("SubArray is found at " + st);
else
System.out.println("SubArray is not found");
}
}
import java.util.Scanner;
public class Array2DstudentsMarks {
Scanner scn = new Scanner(System.in);
String stud[];
int[][] marks;
int[] tot, highestScorer;
int subj, totHighStud;
public static void main(String[] args) {
// STUDENTS MARKS WITH TOTAL - 2D ARRAY
Array2DstudentsMarks twoDArray = new Array2DstudentsMarks();
twoDArray.studentMarksTotal();
twoDArray.dispMarkAndTotal();
}
private void studentMarksTotal() {
System.out.println("Enter no. of Students");
int n = scn.nextInt();
System.out.println("Enter no. of Subjects");
subj = scn.nextInt();
stud = new String[n];
marks = new int[n][subj];
tot = new int[n];
highestScorer= new int[subj];
int maxTot = 0, highScore=0;
for (int i=0; i<n; i++) {
System.out.println("Enter Student name.");
stud[i] = scn.next();
System.out.println("Enter "+subj+" subjects marks of "+stud[i]+" one by one.");
for (int j=0; j<subj; j++) {
marks[i][j] = scn.nextInt();
tot[i] += marks[i][j];
if (marks[highestScorer[j]][j] < marks[i][j]) {
highestScorer[j] = i;
//highScore = marks[i][j];
}
}
if (maxTot < tot[i]) {
maxTot = tot[i];
totHighStud = i;
}
}
}
private void dispMarkAndTotal() {
System.out.println("------------------------------------------------------------------------");
System.out.println(" STUDENTS MARK LIST ");
System.out.println("------------------------------------------------------------------------");
for (int i=0; i<stud.length; i++) {
System.out.println("Student Name : "+stud[i]);
for (int j=0; j<subj; j++) {
System.out.println("Subject-"+(j+1)+" = "+marks[i][j]);
}
System.out.println();
System.out.println("Total Marks = "+tot[i]);
System.out.println("Percentage = "+(tot[i]/subj)+ "%");
System.out.println("------------------------------------------------------------------------");
}
for (int i=0; i<highestScorer.length; i++) {
int student = highestScorer[i];
System.out.println("Subject-"+(i+1)+" Highest Mark is "+marks[student][i]+" achieved by "+stud[student]);
}
System.out.println("------------------------------------------------------------------------");
System.out.println("Over All Highest Total "+tot[totHighStud]+" achieved By "+stud[totHighStud]);
System.out.println("------------------------------------------------------------------------");
}
}
First Letter Occurrence, Last Letter Occurrence in the given Word
Print Reversed Array
Cricketers array and their best score array β Give name as input and get the high score.
package taskPkg;
import java.util.Scanner;
public class ArraysBasics {
//1. PRINTING 1ST LETTER OF THE CHAR ARRAY
//2. PRINT REVERSED A CHAR ARRAY
//3.
public static void main(String[] args) {
// TODO Auto-generated method stub
ArraysBasics obj = new ArraysBasics();
Scanner scn = new Scanner(System.in);
System.out.println("Enter a name to find its first and Last Letter.");
String nam = scn.next();
char[] name = nam.toCharArray();
System.out.println("First Letter of "+nam+" is repeated at "+obj.findFirstLtr(name));
System.out.println("Last Letter of "+nam+" is repeated at "+obj.findLastLtr(name));
obj.printReversedArray(name);
System.out.println();
String[] cricketers = {"Rohit","Suryakumar","Ashwin", "Jadeja","Yashasvi"};
int[] scores = {100,120,86,102,98};
System.out.println("Enter one cricketer name to get his high score");
String givenName = scn.next();
System.out.println("Score for " + givenName+ " is "+obj.getScore(cricketers,scores,givenName));
}
private int findFirstLtr(char name[]) {
char ch = name[0];
for (int i=1; i<name.length; i++) {
if (ch==name[i]) return i;
}
return -1;
}
private int findLastLtr(char name[]) {
char ch = name[name.length-1];
for (int i=0; i<name.length-1; i++) {
if (ch==name[i]) return i;
}
return -1;
}
private void printReversedArray(char[] name) {
System.out.println("Reversed Array = ");
for (int i=name.length-1; i>=0; i--) {
System.out.println(" "+name[i]);
}
}
private int getScore(String[] name, int[] score, String givenName) {
int n = name.length;
for(int i=0; i<n; i++) {
if(name[i].equals(givenName)) return score[i];
}
return 0;
}
}
Armstrong, Neon, Perfect, Prime, emirP, Strong, Triangle Series
import java.util.Scanner;
public class forLoopPlayWithNos {
// USING FOR LOOP
//Code for Armstrong, Neon, Perfect, Prime, emirP, Strong Numbers
// Factorial, SumOfDigits, ReverseDigits, CountOfDigits, Power also used.
//Triangular Series : 1,3,6,10,15,21,28,....
// FOR PRINTING
private static void print(int n, String numType, boolean matched) {
if (matched) System.out.println(n+" is a " + numType +" Number.");
else System.out.println(n+" is not a " + numType +" Number.");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
forLoopPlayWithNos loop = new forLoopPlayWithNos();
System.out.print("Enter a Number to Play = ");
Scanner scn = new Scanner(System.in);
int num = scn.nextInt();
scn.close();
forLoopPlayWithNos.print(num, "ArmStrong",loop.isArmstrongNo(num));
forLoopPlayWithNos.print(num, "Neon", loop.isNeonNo(num));
forLoopPlayWithNos.print(num, "Perfect",loop.isPerfectNo(num));
forLoopPlayWithNos.print(num, "Prime",loop.isPrimeNo(num));
forLoopPlayWithNos.print(num, "emirP",loop.isemirPNo(num));
forLoopPlayWithNos.print(num, "Strong",loop.isStrong(num));
loop.tringangularSeries(num);
}
private boolean isArmstrongNo(int n) {
//Sum of (each digit to the power of (No of digits)) == n
// Ex. 371, 153 == 1^3 + 5^3 + 3^3 = 1+125+27
int powSum=0, nod = countDigits(n);
for (int num=n; num>0; num/=10) {
powSum += findPower((num%10),nod);
}
if (n == powSum) return true;
return false;
}
private boolean isNeonNo(int n) {
//Neon = (Sum of digits of a squared number == number)
// Ex 1,9,45,55
int sqNum = n*n;
if (n == sumOfDigits(sqNum)) return true;
return false;
}
private boolean isPerfectNo(int n) {
//Sum of its divisors (excluding n) == n
//Ex. 6,28,496
int sum=1;
for(int i=2; i<n; i++) {
if (n%i == 0) sum+=i; // Adding Divisors
}
if (sum==n) return true;
return false;
}
private boolean isPrimeNo(int n) {
// N number that can be divided exactly only by itself, ie n's divisors are 1 and n
// Ex 2,3,5,7,11,13
switch(n) {
case 0,1:
return false;
case 2,3:
return true;
default:
if (n%2 == 0) return false;
else {
for (int i=3; i*i<n; i+=2) {
if (n%i == 0) {
return false;
}
}
}
}
return true;
}
private boolean isemirPNo(int n) {
// A number and revereDigits of that number are prime
int rev = reverseDigits(n);
return (isPrimeNo(n) && isPrimeNo(rev))? true:false;
}
private boolean isStrong(int n) {
//sum of the factorial of its digit is equal to number itself
// Ex. 145 = 1!+4!+5!
int sum = 0, num=n;
for (num=n; num>0; num/=10) {
sum += factorial(num%10);
}
return (n == sum)? true:false;
}
private int findPower(int base, int pr) {
// finding base to the power pr
int res=1;
for (; pr>=1; pr--) {
res *= base;
}
return res;
}
private int reverseDigits(int num) {
int rev = 0;
for (; num>0; num/=10) {
rev = rev*10 + num%10;
}
return rev;
}
private int countDigits(int num) { //Counting No. of Digits
int cnt=0;
for (; num>0; num/=10,cnt++);
return cnt;
}
private int sumOfDigits(int n) {
int sum=0;
for (; n>0; n/=10) {
sum += n%10;
}
return sum;
}
private int factorial(int n) {
int fact=1;
for (int i=1; i<=n; i++) {
fact *= i;
}
return fact;
}
private void tringangularSeries(int n) {
System.out.print("Tringangular Series : ");
for (int tri=1, i=2; tri<=n; i++) {
System.out.print(tri+" ");
tri+=i;
}
}
}
package taskPkg;
import java.util.Scanner;
public class PlayingWithNumbers {
//Code for Armstrong, Neon, Perfect, Prime, emirP, Strong Numbers
// Factorial, SumOfDigits, ReverseDigits, CountOfDigits, Power also used.
// FOR PRINTING
private static void print(int n, String numType, boolean givenNumType) {
if (givenNumType) System.out.println(n+" is a " + numType +" Number.");
else System.out.println(n+" is not a " + numType +" Number.");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
PlayingWithNumbers loop = new PlayingWithNumbers();
System.out.print("Enter a Number to Play = ");
Scanner scn = new Scanner(System.in);
int num = scn.nextInt();
scn.close();
PlayingWithNumbers.print(num, "ArmStrong",loop.isArmstrongNo(num));
PlayingWithNumbers.print(num, "Neon", loop.isNeonNo(num));
PlayingWithNumbers.print(num, "Perfect",loop.isPerfectNo(num));
PlayingWithNumbers.print(num, "Prime",loop.isPrimeNo(num));
PlayingWithNumbers.print(num, "emirP",loop.isemirPNo(num));
PlayingWithNumbers.print(num, "Strong",loop.isStrong(num));
}
private boolean isArmstrongNo(int n) {
//Sum of (each digit to the power of No of digits) == n
int num=n, powSum=0, nod = countDigits(num);
while (num > 0) {
powSum += findPower((num%10),nod);
num/=10;
}
if (n == powSum) return true;
return false;
}
private boolean isNeonNo(int n) {
//Neon = (Sum of digits of a squared number == number)
int sqNum = n*n;
if (n == sumOfDigits(sqNum)) return true;
return false;
}
private boolean isPerfectNo(int n) {
//Sum of its divisors (excluding n) == n
int i=2, sum=1;
while (i<n) {
if (n%i == 0) sum+=i; // Adding Divisors
i++;
}
if (sum==n) return true;
return false;
}
private boolean isPrimeNo(int n) {
// N number that can be divided exactly only by itself, ie n's divisors are 1 and n
if (n<=1 || n%2 == 0) return false;
if (n<=3) return true;
int i=3;
while (i < n) {
if (n%i == 0) {
return false;
}
i+=2;
}
return true;
}
private boolean isemirPNo(int n) {
// A number and revereDigits of that number are prime
int rev = reverseDigits(n);
return (isPrimeNo(n) && isPrimeNo(rev))? true:false;
}
private boolean isStrong(int n) {
//sum of the factorial of its digit is equal to number itself
// Ex. 145 = 1!+4!+5!
int sum = 0, num=n;
while (num>0) {
sum += factorial(num%10);
num/=10;
}
return (n == sum)? true:false;
}
private int findPower(int base, int pr) {
// finding base to the power pr
int res=1;
while (pr>=1) {
res *= base;
pr--;
}
return res;
}
private int reverseDigits(int num) {
int rev = 0;
while (num>0) {
rev = rev*10 + num%10;
num/=10;
}
return rev;
}
private int countDigits(int num) { //Counting No. of Digits
int cnt=0;
while (num>0) {
num/=10;
cnt++;
}
return cnt;
}
private int sumOfDigits(int n) {
int sum=0;
while (n>0) {
sum += n%10;
n/=10;
}
return sum;
}
private int factorial(int n) {
int i=1,fact=1;
while (i<=n) {
fact *= i;
i++;
}
return fact;
}
}
Java provides a variety of methods for manipulating and working with strings through the String class. Hereβs a rundown of some of the most commonly used methods: Basic Methods Case Conversion Trimming and Padding Searching and Replacing Splitting and Joining Comparison Utility Methods These methods cover a wide range of string manipulation needs in Java. [β¦]
ArrayList is a part of Javaβs java.util package and provides a dynamic array capable of growing as needed. Here are some commonly used methods in ArrayList: Adding Elements Accessing Elements Removing Elements Size and Capacity Searching and Checking Other Operations Iteration These methods provide a comprehensive set of operations for manipulating and accessing elements in [β¦]
java programming language an interface is a reference type, similar to a class, that can contain only constants, method declaration(method signature, nobody), default methods, static methods and nested types inside its body. Nested type simply means it can contain another interface or class inside it. variables declared in an interface are public, static & final [β¦]
A Collection represents a single unit of objects What is a framework in Java What Is a Collections Framework? A collections framework is a unified architecture for representing and manipulating collections. All collections frameworks contain the following: About Collection Benefits of the Java Collections Framework Hierarchy of Collection Framework Reference : https://docs.oracle.com/javase/tutorial/collections/intro/index.html Reference : https://www.javatpoint.com/collections-in-java