{"id":1305,"date":"2021-11-04T19:08:36","date_gmt":"2021-11-04T19:08:36","guid":{"rendered":"https:\/\/rahulshettyacademy.com\/blog\/?p=1305"},"modified":"2021-11-30T18:51:53","modified_gmt":"2021-11-30T18:51:53","slug":"sdet-interview-questions-part-5","status":"publish","type":"post","link":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2021\/11\/04\/sdet-interview-questions-part-5\/","title":{"rendered":"Sr.QA and SDET Interview Questions in Java &#8211; Part 5"},"content":{"rendered":"<h3 id=\"t-1636051989137\"><a name=\"_Toc82204599\" style=\"outline: none;\">1. Write a program to sort ArrayList using Comparable and Comparator<\/a><\/h3>\n<p><strong>Solution: Sort ArrayList using Comparable<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">import java.util.ArrayList;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">import java.util.Collections;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">\/\/Using Comparable<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">class Employee implements Comparable&lt;Employee&gt; {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; &nbsp;private String name;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; &nbsp;private int empId;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; &nbsp;private int age;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; &nbsp;public Employee(String name, int empId, int age) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;this.name= name;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;this.empId=empId;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;this.age=age;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; &nbsp;}<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; &nbsp;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; @Override<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public int compareTo(Employee employee) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;return this.age &#8211; employee.age;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; @Override<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public String toString() {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;return &#8220;[ Name= &#8221; + name + &#8220;, Employee Id = &#8221; + empId + &#8220;, Employee age = &#8221; + age + &#8220;]&#8221;;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">class Main {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static void main(String[] args) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ArrayList&lt;Employee&gt; list = new ArrayList&lt;Employee&gt;();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add(new Employee(&#8220;Rahul&#8221;,6589586,35));<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add(new Employee(&#8220;John&#8221;,854756,30));<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add(new Employee(&#8220;Robin&#8221;,784125,32));<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;Collections.sort(list);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;for(Employee e: list){<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(e);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(92, 183, 40);\">Output:<\/span><\/p>\n<p><span style=\"color: rgb(92, 183, 40);\">[ Name= John, Employee Id = 854756, Employee age = 30]<\/span><\/p>\n<p><span style=\"color: rgb(92, 183, 40);\">[ Name= Robin, Employee Id = 784125, Employee age = 32]<\/span><\/p>\n<p><span style=\"color: rgb(92, 183, 40);\">[ Name= Rahul, Employee Id = 6589586, Employee age = 35]<\/span><\/p>\n<p><strong>Solution: Sort ArrayList using Comparator<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">import java.util.ArrayList;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">import java.util.Collections;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">import java.util.Comparator;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">\/\/Using Comparator<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">class Employee {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; private String name;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; private int empId;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; private int age;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public Employee(String name, int empId, int age) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.name = name;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.empId = empId;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.age = age;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public String getName() {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return this.name;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public int getEmpId() {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return this.empId;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public int getAge() {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return this.age;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static Comparator&lt;Employee&gt; EmployeeNameComparator = new Comparator&lt;Employee&gt;() {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public int compare(Employee e1, Employee e2) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String empName1 = e1.getName().toLowerCase();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String empName2 = e2.getName().toLowerCase();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return empName1.compareTo(empName2);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; };<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static Comparator&lt;Employee&gt; EmployeeAgeComparator = new Comparator&lt;Employee&gt;() {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public int compare(Employee e1, Employee e2) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int empAge1 = e1.getAge();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int empAge2 = e2.getAge();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return empAge1 &#8211; empAge2;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; };<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; @Override<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public String toString() {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return &#8220;[ Name= &#8221; + name + &#8220;, Employee Id = &#8221; + empId + &#8220;, Employee age = &#8221; + age + &#8220;]&#8221;;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">class Main {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static void main(String[] args) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ArrayList&lt;Employee&gt; list = new ArrayList&lt;Employee&gt;();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add(new Employee(&#8220;Rahul&#8221;, 6589586, 35));<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add(new Employee(&#8220;John&#8221;, 854756, 32));<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add(new Employee(&#8220;Lukas&#8221;, 784125, 30));<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;Sort Employee List by Name&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Collections.sort(list, Employee.EmployeeNameComparator);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (Employee e : list) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(e);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;nSort Employee List by Age&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Collections.sort(list, Employee.EmployeeAgeComparator);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (Employee e : list) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(e);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(37, 217, 59);\">Output:<\/span><\/p>\n<p><span style=\"color: rgb(37, 217, 59);\">Sort Employee List by Name<\/span><\/p>\n<p><span style=\"color: rgb(37, 217, 59);\">[ Name= John, Employee Id = 854756, Employee age = 32]<\/span><\/p>\n<p><span style=\"color: rgb(37, 217, 59);\">[ Name= Lukas, Employee Id = 784125, Employee age = 30]<\/span><\/p>\n<p><span style=\"color: rgb(37, 217, 59);\">[ Name= Rahul, Employee Id = 6589586, Employee age = 35]<\/span><\/p>\n<p><span style=\"color: rgb(37, 217, 59);\">Sort Employee List by Age<\/span><\/p>\n<p><span style=\"color: rgb(37, 217, 59);\">[ Name= Lukas, Employee Id = 784125, Employee age = 30]<\/span><\/p>\n<p><span style=\"color: rgb(37, 217, 59);\">[ Name= John, Employee Id = 854756, Employee age = 32]<\/span><\/p>\n<p><span style=\"color: rgb(37, 217, 59);\">[ Name= Rahul, Employee Id = 6589586, Employee age = 35]<\/span><\/p>\n<h3 id=\"t-1636051989138\"><a name=\"_Toc82204600\" style=\"outline: none;\">2. I have arrayList like <em>[Test1, Test2, Test3, Test4, Test5]<\/em> Write a Program to replace the &#8220;Test2&#8221; with string &#8220;ReplacedTest&#8221;<\/a><\/h3>\n<p><strong>Solution:<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">import java.util.ArrayList;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">class Main {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static void main(String[] args) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ArrayList&lt;String&gt;&nbsp; list = new ArrayList&lt;String&gt;();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add(&#8220;Test1&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add(&#8220;Test1&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add(&#8220;Test2&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add(&#8220;Test3&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add(&#8220;Test4&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;ArrayList before Replace&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(list);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int index = list.indexOf(&#8220;Test2&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.set(index,&#8221;ReplacedTest&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;nArrayList after Replace&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(list);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(29, 177, 33);\">Output:<\/span><\/p>\n<p><span style=\"color: rgb(29, 177, 33);\">ArrayList before Replace<\/span><\/p>\n<p><span style=\"color: rgb(29, 177, 33);\">[Test1, Test1, Test2, Test3, Test4]<\/span><\/p>\n<p><span style=\"color: rgb(29, 177, 33);\">ArrayList after Replace<\/span><\/p>\n<p><span style=\"color: rgb(29, 177, 33);\">[Test1, Test1, ReplacedTest, Test3, Test4]<\/span><\/p>\n<h3 id=\"t-1636051989139\"><a name=\"_Toc82204601\" style=\"outline: none;\">3. Write a Java program to insert the specified element at the end of a linked list<\/a><\/h3>\n<p><strong>Solution:<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">import java.util.LinkedList;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">class Main {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static void main(String[] args) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LinkedList&lt;String&gt;&nbsp; list = new LinkedList&lt;String&gt;();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add(&#8220;Test1&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add(&#8220;Test1&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add(&#8220;Test2&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add(&#8220;Test3&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add(&#8220;Test4&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;LinkedList before Inserting Element at the End\/Last&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(list);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.offerLast(&#8220;LastInsertedElement&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;nLinkedList after Inserting Element at the End\/Last&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(list);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(20, 237, 39);\">Output:<\/span><\/p>\n<p><span style=\"color: rgb(20, 237, 39);\">LinkedList before Inserting Element at the End\/Last<\/span><\/p>\n<p><span style=\"color: rgb(20, 237, 39);\">[Test1, Test1, Test2, Test3, Test4]<\/span><\/p>\n<p><span style=\"color: rgb(20, 237, 39);\">LinkedList after Inserting Element at the End\/Last<\/span><\/p>\n<p><span style=\"color: rgb(20, 237, 39);\">[Test1, Test1, Test2, Test3, Test4, LastInsertedElement]<\/span><\/p>\n<h3 id=\"t-1636051989140\"><a name=\"_Toc82204602\" style=\"outline: none;\">4. Write a program to perform Pairwise swap elements of a given linked list<\/a><\/h3>\n<p>In Pairwise swapping each pair will be swapped<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>Input&nbsp; 1 &gt; 2 &gt; 3 &gt; 4 &gt; 5<\/p>\n<p>Output 2 &gt; 1 &gt; 4 &gt; 3 &gt; 5<\/p>\n<p><strong>Solution:<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">\/\/Pairwise Swap<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">public class LinkedList {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; Node head;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; class Node {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int data;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node next;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node(int d)<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data = d;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; next = null;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; void pairWiseSwap()<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node temp = head;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (temp != null &amp;&amp; temp.next != null) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int k = temp.data;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp.data = temp.next.data;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp.next.data = k;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp = temp.next.next;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public void push(int new_data)<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node new_node = new Node(new_data);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new_node.next = head;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; head = new_node;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; void print()<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node temp = head;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (temp != null) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.print(temp.data + &#8221; &#8220;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp = temp.next;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static void main(String args[])<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LinkedList list = new LinkedList();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.push(5);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.push(4);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.push(3);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.push(2);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.push(1);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;Linked List before PairWise Swap &#8220;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.print();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.pairWiseSwap();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;Linked List after PairWise Swap&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.print();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(46, 193, 73);\">Output:<\/span><\/p>\n<p><span style=\"color: rgb(46, 193, 73);\">Linked List before PairWise Swap<\/span><\/p>\n<p><span style=\"color: rgb(46, 193, 73);\">1 2 3 4 5<\/span><\/p>\n<p><span style=\"color: rgb(46, 193, 73);\">Linked List after PairWise Swap<\/span><\/p>\n<p><span style=\"color: rgb(46, 193, 73);\">2 1 4 3 5<\/span><\/p>\n<h3 id=\"t-1636051989141\"><a name=\"_Toc82204603\" style=\"outline: none;\">5. Check if two arrays have same number of items and values<\/a><\/h3>\n<p><a name=\"_Toc82204603\" style=\"outline: none;\">Consider I have two arrays<\/a><\/p>\n<p>a = [1,2,3,4]<\/p>\n<p>b = [2,1,4,3]<\/p>\n<p>Considering the above array, We have the same Item in both the arrays, but the index is different<\/p>\n<p>Write a program to check a is having the same number of items and same values compared with b<\/p>\n<p>You should not use Arrays.Equals() method<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Solution:<\/strong><\/p>\n<p>There are two requirements here<\/p>\n<p>1. Number of Elements in a[] should be same as b[] \/\/a.length == b.length<\/p>\n<p>2. Both a[] and b[] should have the same element, order sequence can be different<\/p>\n<p>3. You should not use Arrays.Equals method<\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">import java.util.Arrays;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">public class Main {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static void main(String args[]) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int[] array1 = { 1, 2, 3, 4 };<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int[] array2 = { 2, 1, 4, 3 };<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; boolean b = false;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (array1.length != array2.length) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;b = false;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Arrays.sort(array1);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Arrays.sort(array2);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(int i=0;i&lt;array1.length;i++) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(array1[i]!=array2[i]) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b=false;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b=true;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (b)<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;Arrays are having same values&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;Arrays are not having same values&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(55, 173, 34);\">Output:<\/span><\/p>\n<p><span style=\"color: rgb(55, 173, 34);\">Arrays are having same values<\/span><\/p>\n<h3 id=\"t-1636051989142\"><a name=\"_Toc82204604\" style=\"outline: none;\">6. Write a Java Program to find the largest and smallest word in a string<\/a><\/h3>\n<p><strong>Solution:<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">public class Main {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; &nbsp;public static void main(String[] args){<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;String string = &#8220;Rahul Shetty Academy is the best&#8221;;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;String[] words = string.trim().replaceAll(&#8220;\\s+&#8221;, &#8221; &#8220;).split(&#8221; &#8220;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String shortest = words[0];<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String longest =&nbsp; words[0];<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(String word : words){<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(word.length() &lt; shortest.length()){<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shortest = word;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(word.length() &gt; longest.length()){<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; longest = word;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println(&#8220;The Shortest Word = &#8220;+shortest);&nbsp;&nbsp;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println(&#8220;The Longest Word = &#8220;+ longest);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; &nbsp; }&nbsp;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(36, 210, 36);\">Output:<\/span><\/p>\n<p><span style=\"color: rgb(36, 210, 36);\">The Shortest Word = is<\/span><\/p>\n<p><span style=\"color: rgb(36, 210, 36);\">The Longest Word = Academy<\/span><\/p>\n<h3 id=\"t-1636051989143\"><a name=\"_Toc82204605\" style=\"outline: none;\">7. Java Program to Check if a Given Number is Perfect Square<\/a><\/h3>\n<p>A perfect square is a positive integer, it is the product of the number itself<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>49 = 7*7, So the 49 is Perfect Square<\/p>\n<p><strong>Solution:<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">class Main {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; static boolean isPerfectSquare(int x)<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (x &gt;= 0) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int sqrt = (int)Math.sqrt(x);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ((sqrt*sqrt) == x);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static void main(String[] args)<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int x = 8100;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (isPerfectSquare(x))<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.print(&#8220;Given Number is a Perfect Square&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.print(&#8220;Given Number is Not a Perfect Square&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(34, 179, 42);\">Output:<\/span><\/p>\n<p><span style=\"color: rgb(34, 179, 42);\">Given Number is a Perfect Square<\/span><\/p>\n<h3 id=\"t-1636051989144\"><a name=\"_Toc82204606\" style=\"outline: none;\">8. Write a Program to cover all major concepts of OOPs<\/a><\/h3>\n<p><em>Note: There are multiple ways to write this program, we have shown one way.<\/em><\/p>\n<p><strong>Solution:<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">\/\/Abstraction<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">interface Car {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; void printName();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">\/\/Inheritance<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">class Ford {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; private String name; \/\/Encapsulation<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public String getName() {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return name;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public void setName(String newName) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name = newName;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">class OneMore extends Ford implements Car{<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; @Override \/\/Overriding<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public void printName() {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;Override Method Print &#8221; + super.getName());<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; \/\/Overloading<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public void printName(String string) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;Overloaded Method Print &#8221; + string);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">class Main {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static void main(String[] args) {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OneMore object = new OneMore();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; object.setName(&#8220;Eco Sport&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; object.printName();<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; object.printName(&#8220;Aspire&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(39, 187, 24);\">Output:<\/span><\/p>\n<p><span style=\"color: rgb(39, 187, 24);\">Overloading Print Eco Sport<\/span><\/p>\n<p><span style=\"color: rgb(39, 187, 24);\">Overloading Print Aspire<\/span><\/p>\n<h3 id=\"t-1636051989145\"><a name=\"_Toc82204607\" style=\"outline: none;\">9. Write a program to find the length of the string without using string.length();<\/a><\/h3>\n<p><em>Note: There are multiple ways to write this program, we have shown one way.<\/em><\/p>\n<p><em> <\/em><\/p>\n<p><strong>Solution:<\/strong><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">public class Main<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">{<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; static int i,c,res;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; static void length(String s)<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp; &nbsp;{<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(i=0,c=0;0&lt;=i;i++,c++)<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s.charAt(i);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch(StringIndexOutOfBoundsException e)<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; System.out.println(&#8220;&#8221;);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.print(&#8220;The length of the string &#8220;&#8221;+s+&#8221;&#8221; is &#8221; +c);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; public static void main (String args[])<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; {<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String string = &#8220;Rahul Shetty Academy&#8221;;<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; length(string);<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p><span style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span style=\"color: rgb(33, 163, 60);\">Output:<\/span><\/p>\n<p><span style=\"color: rgb(33, 163, 60);\">The length of the string &#8220;Rahul Shetty Academy&#8221; is 20<\/span><\/p>\n<h5 style=\"text-align: center;\"><em><span style=\"text-decoration: underline;\">Course Alert<\/span><\/em><\/h5>\n<p><strong>If you are interested in landing a SDET or Sr. QA Automation Engineer role, check out our popular SDET course to learn the fundamental skills required an SDET needs to perform at work. Also, I have another popular course which covers Top 150+ Interview questions most commonly asked in SDET \/ Automation interviews.<\/strong><\/p>\n<ul>\n<li><span><a href=\"https:\/\/courses.rahulshettyacademy.com\/p\/sdet-test-architect-essentials-road-to-full-stack-qa\" target=\"_blank\" style=\"outline: none;\" rel=\"noopener noreferrer\">SDET\/Test Architect Essentials -Road to Full stack QA<\/a><\/span><\/li>\n<li><span><a href=\"https:\/\/courses.rahulshettyacademy.com\/p\/sdet-qa-automation-interview-kit-java-logic-programs\" target=\"_blank\" style=\"outline: none;\" rel=\"noopener noreferrer\">SDET\/QA Automation Interview Kit + Java logic Programs<\/a><\/span><\/li>\n<\/ul>\n<h4><em><strong>A Quick Note<\/strong><\/em><\/h4>\n<p>Please remember all these courses comes with <strong>100% Lifetime acces<\/strong><strong>s<\/strong> and <strong>free updates for Lifetime!!<\/strong><\/p>\n<p>With this we end the 5-part series of Sr.QA and SDET Interview Questions in Java. Please click on the link <strong><em><a href=\"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2021\/07\/31\/top-30-api-testing-interview-questions-and-answers\/\" target=\"_blank\" style=\"outline: none;\" rel=\"noopener noreferrer\">Top 30 API Testing Interview Questions and Answers \u2013 Part 1<\/a><\/em><\/strong> to where we will cover Top API Interview questions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Write a program to sort ArrayList using Comparable and Comparator Solution: Sort ArrayList using Comparable import java.util.ArrayList; import java.util.Collections; \/\/Using Comparable class Employee implements Comparable&lt;Employee&gt; { &nbsp;&nbsp;&nbsp; &nbsp;private String name; &nbsp;&nbsp;&nbsp; &nbsp;private int empId; &nbsp;&nbsp;&nbsp; &nbsp;private int age; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;public Employee(String name, int empId, int age) { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;this.name= name; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;this.empId=empId; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1306,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-1305","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-interview-questions","post-wrapper","thrv_wrapper"],"_links":{"self":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1305","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=1305"}],"version-history":[{"count":15,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1305\/revisions"}],"predecessor-version":[{"id":1365,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1305\/revisions\/1365"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/media\/1306"}],"wp:attachment":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}