{"id":1305,"date":"2021-11-04T19:08:36","date_gmt":"2021-11-04T19:08:36","guid":{"rendered":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2021\/11\/04\/sdet-interview-questions-part-5\/"},"modified":"2021-11-04T19:08:36","modified_gmt":"2021-11-04T19:08:36","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":"Top SDET Interview Questions in Java &#8211; Part 5"},"content":{"rendered":"<p><html><body><\/p>\n<section class=\"tcb-post-content tcb-shortcode thrv_wrapper\" data-css=\"tve-u-16ec5d248bb\">\n<div class=\"tve_flt tcb-style-wrap\" id=\"tve_flt\">\n<div class=\"tve_shortcode_editor tar-main-content\" data-post-id=\"1305\" id=\"tve_editor\">\n<div class=\"thrv_wrapper tve-toc tve-elem-scroll tve-toc-expandable tcb-local-vars-root\" data-animation=\"slide\" data-animation-speed=\"fast\" data-bullet-style='{\"0\":\"tve-u-17399ffbddd\",\"1\":\"tve-u-1739a0466e5\",\"2\":\"tve-u-1739a04a2bb\"}' data-columns=\"1\" data-columns-d=\"1\" data-css=\"tve-u-17cec4dc3dc\" data-ct=\"toc-60671\" data-ct-name=\"Table of Contents 03\" data-element-name=\"Table of Contents\" data-headers=\"h1,h3,h5\" data-heading-style='{\"0\":\"tve-u-17cec4dc3e1\",\"1\":\"tve-u-17cec4dc3e3\",\"2\":\"tve-u-17cec4dc3e4\"}' data-highlight=\"section\" data-number-style='{\"0\":\"tve-u-17cec4dc3e2\",\"1\":\"tve-u-173dc888a58\",\"2\":\"tve-u-173dc8891dc\"}' data-numbering=\"basic\" data-state-default=\"expanded\" data-state-default-m=\"collapsed\" data-transition=\"fade\" style=\"\">\n<div class=\"thrive-colors-palette-config\" style=\"display: none !important\"><\/div>\n<div class=\"tve-toc-divider\" style=\"position: absolute; width: 0; height: 0; overflow: hidden;\">\n<div class=\"thrv_wrapper thrv-divider tve-vert-divider\" data-color-d=\"rgba(0, 0, 0, 0)\" data-css=\"tve-u-17cec4dc3dd\" data-style=\"tve_sep-1\" data-thickness-d=\"1\">\n<hr class=\"tve_sep tve_sep-1\" style=\"\"\/><\/div>\n<\/div>\n<p><svg class=\"toc-icons\" style=\"position: absolute; width: 0; height: 0; overflow: hidden;\" version=\"1.1\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"><symbol data-id=\"icon-circle-outlined\" id=\"toc-bullet-0\" viewbox=\"0 0 512 512\"><path d=\"M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200z\"><\/path><\/symbol><symbol data-id=\"icon-circle-outlined\" id=\"toc-bullet-1\" viewbox=\"0 0 512 512\"><path d=\"M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200z\"><\/path><\/symbol><symbol data-id=\"icon-circle-outlined\" id=\"toc-bullet-2\" viewbox=\"0 0 512 512\"><path d=\"M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200z\"><\/path><\/symbol><\/svg><\/p>\n<div class=\"tve-content-box-background\" data-css=\"tve-u-17cec4dc3de\" style=\"\"><\/div>\n<div class=\"thrv_wrapper tve-toc-title show-icon tcb-icon-display tve-no-dropzone tve-prevent-content-edit\" data-css=\"tve-u-17cec4dc3df\" style=\"\">\n<div class=\"tve-content-box-background\"><\/div>\n<div class=\"tve-cb\" style=\"\">\n<div class=\"tve-toc-title-icon\" data-icon-code=\"icon-arrow-circle-down-solid\" style=\"\"><svg class=\"tcb-icon\" data-id=\"icon-arrow-circle-down-solid\" data-name=\"\" viewbox=\"0 0 512 512\"><path d=\"M504 256c0 137-111 248-248 248S8 393 8 256 119 8 256 8s248 111 248 248zm-143.6-28.9L288 302.6V120c0-13.3-10.7-24-24-24h-16c-13.3 0-24 10.7-24 24v182.6l-72.4-75.5c-9.3-9.7-24.8-9.9-34.3-.4l-10.9 11c-9.4 9.4-9.4 24.6 0 33.9L239 404.3c9.4 9.4 24.6 9.4 33.9 0l132.7-132.7c9.4-9.4 9.4-24.6 0-33.9l-10.9-11c-9.5-9.5-25-9.3-34.3.4z\"><\/path><\/svg><\/div>\n<div class=\"thrv_wrapper thrv_text_element tve_no_icons\">\n<div class=\"tcb-plain-text\" style=\"\">Table of Contents<\/div>\n<\/p><\/div>\n<\/div>\n<\/div>\n<div class=\"tve-cb tve-toc-content tve-prevent-content-edit\" style=\"\">\n<div class=\"thrv_wrapper tve-toc-list tcb-no-delete tcb-no-save tcb-no-clone tve-no-dropzone\" data-css=\"tve-u-17cec4dc3e0\" style=\"\">\n<div class=\"tve-content-box-background\"><\/div>\n<div class=\"tve-cb\" style=\"\">\n<div class=\"tve_ct_content tve_clearfix\" style=\"\">\n<div class=\"ct_column\">\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17cec4dc3e3\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1636051989137\" jump-animation=\"smooth\">1. Write a program to sort ArrayList using Comparable and Comparator<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17cec4dc3e3\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1636051989138\" jump-animation=\"smooth\">2. I have arrayList like [Test1, Test2, Test3, Test4, Test5] Write a Program to replace the &#8220;Test2&#8221; with string &#8220;ReplacedTest&#8221;<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17cec4dc3e3\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1636051989139\" jump-animation=\"smooth\">3. Write a Java program to insert the specified element at the end of a linked list<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17cec4dc3e3\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1636051989140\" jump-animation=\"smooth\">4. Write a program to perform Pairwise swap elements of a given linked list<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17cec4dc3e3\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1636051989141\" jump-animation=\"smooth\">5. Check if two arrays have same number of items and values<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17cec4dc3e3\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1636051989142\" jump-animation=\"smooth\">6. Write a Java Program to find the largest and smallest word in a string<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17cec4dc3e3\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1636051989143\" jump-animation=\"smooth\">7. Java Program to Check if a Given Number is Perfect Square<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17cec4dc3e3\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1636051989144\" jump-animation=\"smooth\">8. Write a Program to cover all major concepts of OOPs<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-17cec4dc3e3\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1636051989145\" jump-animation=\"smooth\">9. Write a program to find the length of the string without using string.length();<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level2 tve_no_icons\" data-css=\"tve-u-17cec4dc3e4\" data-element-name=\"Heading Level 3\" data-tag=\"H5\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1638298068412\" jump-animation=\"smooth\">Course Alert<\/a><\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv-divider tve-vert-divider\" data-color-d=\"rgba(0, 0, 0, 0)\" data-css=\"tve-u-17cec4dc3dd\" data-style=\"tve_sep-1\" data-thickness-d=\"1\">\n<hr class=\"tve_sep tve_sep-1\" style=\"\"\/><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\" id=\"t-1636051989137\"><a class=\"tve-froala fr-basic\" 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<div class=\"code-block code-block-2\" style=\"margin: 8px auto; text-align: center; display: block; clear: both;\">\n<p><!-- horizontal responsive 2 --><br \/>\n<ins class=\"adsbygoogle\" data-ad-client=\"ca-pub-3231318496783163\" data-ad-format=\"auto\" data-ad-slot=\"2788468763\" data-full-width-responsive=\"true\" style=\"display:block\"><\/ins>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\" style=\"height: auto !important; min-height: 0px !important;\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\" style=\"height: auto !important; min-height: 0px !important;\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17cec4e7995\" style=\"height: auto !important;\">\n<p><span data-css=\"tve-u-17cec58ca0d\" style=\"color: rgb(255, 255, 255);\">import java.util.ArrayList;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca0f\" style=\"color: rgb(255, 255, 255);\">import java.util.Collections;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca10\" style=\"color: rgb(255, 255, 255);\">\/\/Using Comparable<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca12\" style=\"color: rgb(255, 255, 255);\">class Employee implements Comparable&lt;Employee&gt; {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca13\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 \u00a0private String name;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca14\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 \u00a0private int empId;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca16\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 \u00a0private int age;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca17\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca19\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 \u00a0public Employee(String name, int empId, int age) {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca1a\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0this.name= name;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca1c\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0this.empId=empId;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca1d\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0this.age=age;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca1e\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 \u00a0}<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca20\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 \u00a0<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca21\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 @Override<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca23\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public int compareTo(Employee employee) {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca24\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0return this.age &#8211; employee.age;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca26\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca27\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca28\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 @Override<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca2a\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public String toString() {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca2b\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0return &#8220;[ Name= &#8221; + name + &#8220;, Employee Id = &#8221; + empId + &#8220;, Employee age = &#8221; + age + &#8220;]&#8221;;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca2d\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca2e\" style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca2f\" style=\"color: rgb(255, 255, 255);\">class Main {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca31\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public static void main(String[] args) {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca32\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ArrayList&lt;Employee&gt; list = new ArrayList&lt;Employee&gt;();<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca34\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.add(new Employee(&#8220;Rahul&#8221;,6589586,35));<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca35\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.add(new Employee(&#8220;John&#8221;,854756,30));<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca37\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.add(new Employee(&#8220;Robin&#8221;,784125,32));<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca38\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca39\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0Collections.sort(list);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca3b\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0for(Employee e: list){<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca3c\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(e);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca3e\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca3f\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec58ca41\" style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4ea33d\" style=\"color: rgb(92, 183, 40);\">Output:<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4ea33f\" style=\"color: rgb(92, 183, 40);\">[ Name= John, Employee Id = 854756, Employee age = 30]<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4ea341\" style=\"color: rgb(92, 183, 40);\">[ Name= Robin, Employee Id = 784125, Employee age = 32]<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4ea342\" style=\"color: rgb(92, 183, 40);\">[ Name= Rahul, Employee Id = 6589586, Employee age = 35]<\/span><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p><strong>Solution: Sort ArrayList using Comparator<\/strong><\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17cec4ee804\" style=\"\">\n<p><span data-css=\"tve-u-17cec4f5414\" style=\"color: rgb(255, 255, 255);\">import java.util.ArrayList;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5416\" style=\"color: rgb(255, 255, 255);\">import java.util.Collections;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5418\" style=\"color: rgb(255, 255, 255);\">import java.util.Comparator;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5419\" style=\"color: rgb(255, 255, 255);\">\/\/Using Comparator<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f541b\" style=\"color: rgb(255, 255, 255);\">class Employee {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f541c\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 private String name;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f541d\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 private int empId;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f541e\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 private int age;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5420\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public Employee(String name, int empId, int age) {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5421\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 this.name = name;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5422\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 this.empId = empId;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5424\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 this.age = age;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5425\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5426\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public String getName() {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5428\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return this.name;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5429\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f542a\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public int getEmpId() {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f542c\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return this.empId;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f542d\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f542e\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public int getAge() {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f542f\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return this.age;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5431\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5432\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public static Comparator&lt;Employee&gt; EmployeeNameComparator = new Comparator&lt;Employee&gt;() {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5433\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public int compare(Employee e1, Employee e2) {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5435\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 String empName1 = e1.getName().toLowerCase();<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5436\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 String empName2 = e2.getName().toLowerCase();<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5437\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return empName1.compareTo(empName2);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5438\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f543a\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 };<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f543b\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public static Comparator&lt;Employee&gt; EmployeeAgeComparator = new Comparator&lt;Employee&gt;() {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f543c\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public int compare(Employee e1, Employee e2) {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f543e\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int empAge1 = e1.getAge();<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f543f\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int empAge2 = e2.getAge();<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5440\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return empAge1 &#8211; empAge2;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5442\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5443\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 };<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5444\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 @Override<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5445\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public String toString() {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5447\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return &#8220;[ Name= &#8221; + name + &#8220;, Employee Id = &#8221; + empId + &#8220;, Employee age = &#8221; + age + &#8220;]&#8221;;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5448\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5449\" style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f544b\" style=\"color: rgb(255, 255, 255);\">class Main {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f544c\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public static void main(String[] args) {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f544d\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ArrayList&lt;Employee&gt; list = new ArrayList&lt;Employee&gt;();<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f544f\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.add(new Employee(&#8220;Rahul&#8221;, 6589586, 35));<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5450\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.add(new Employee(&#8220;John&#8221;, 854756, 32));<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5451\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.add(new Employee(&#8220;Lukas&#8221;, 784125, 30));<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5453\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(&#8220;Sort Employee List by Name&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5454\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Collections.sort(list, Employee.EmployeeNameComparator);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5455\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 for (Employee e : list) {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5456\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(e);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5458\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5459\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(&#8220;nSort Employee List by Age&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f545a\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Collections.sort(list, Employee.EmployeeAgeComparator);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f545c\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 for (Employee e : list) {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f545d\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(e);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f545e\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f545f\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5461\" style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f5462\" style=\"color: rgb(37, 217, 59);\">Output:<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f9734\" style=\"color: rgb(37, 217, 59);\">Sort Employee List by Name<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f9736\" style=\"color: rgb(37, 217, 59);\">[ Name= John, Employee Id = 854756, Employee age = 32]<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f9737\" style=\"color: rgb(37, 217, 59);\">[ Name= Lukas, Employee Id = 784125, Employee age = 30]<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f9738\" style=\"color: rgb(37, 217, 59);\">[ Name= Rahul, Employee Id = 6589586, Employee age = 35]<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f973a\" style=\"color: rgb(37, 217, 59);\">Sort Employee List by Age<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f973b\" style=\"color: rgb(37, 217, 59);\">[ Name= Lukas, Employee Id = 784125, Employee age = 30]<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f973c\" style=\"color: rgb(37, 217, 59);\">[ Name= John, Employee Id = 854756, Employee age = 32]<\/span><\/p>\n<p><span data-css=\"tve-u-17cec4f546c\" style=\"color: rgb(37, 217, 59);\">[ Name= Rahul, Employee Id = 6589586, Employee age = 35]<\/span><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\" id=\"t-1636051989138\"><a class=\"tve-froala fr-basic\" 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<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17cec50a8ca\" style=\"\">\n<p><span data-css=\"tve-u-17cec50cedc\" style=\"color: rgb(255, 255, 255);\">import java.util.ArrayList;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec50cede\" style=\"color: rgb(255, 255, 255);\">class Main {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec50cee0\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public static void main(String[] args) {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec50cee1\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ArrayList&lt;String&gt;\u00a0 list = new ArrayList&lt;String&gt;();<\/span><\/p>\n<p><span data-css=\"tve-u-17cec50cee3\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.add(&#8220;Test1&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec50cee4\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.add(&#8220;Test1&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec50cee6\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.add(&#8220;Test2&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec50cee7\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.add(&#8220;Test3&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec50cee9\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.add(&#8220;Test4&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec50ceea\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/p>\n<p><span data-css=\"tve-u-17cec50ceeb\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(&#8220;ArrayList before Replace&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec50ceed\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(list);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec50ceee\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/p>\n<p><span data-css=\"tve-u-17cec50cef0\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int index = list.indexOf(&#8220;Test2&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec50cef1\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.set(index,&#8221;ReplacedTest&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec50cef3\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/p>\n<p><span data-css=\"tve-u-17cec50cef5\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(&#8220;nArrayList after Replace&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec50cef6\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(list);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec50cef8\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec50cef9\" style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span data-css=\"tve-u-17cec50cefa\" style=\"color: rgb(29, 177, 33);\">Output:<\/span><\/p>\n<p><span data-css=\"tve-u-17cec5106a4\" style=\"color: rgb(29, 177, 33);\">ArrayList before Replace<\/span><\/p>\n<p><span data-css=\"tve-u-17cec5106a5\" style=\"color: rgb(29, 177, 33);\">[Test1, Test1, Test2, Test3, Test4]<\/span><\/p>\n<p><span data-css=\"tve-u-17cec5106a7\" style=\"color: rgb(29, 177, 33);\">ArrayList after Replace<\/span><\/p>\n<p><span data-css=\"tve-u-17cec50cf00\" style=\"color: rgb(29, 177, 33);\">[Test1, Test1, ReplacedTest, Test3, Test4]<\/span><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\" id=\"t-1636051989139\"><a class=\"tve-froala fr-basic\" 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<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17cec519caf\" style=\"\">\n<p><span data-css=\"tve-u-17cec51bf21\" style=\"color: rgb(255, 255, 255);\">import java.util.LinkedList;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51bf23\" style=\"color: rgb(255, 255, 255);\">class Main {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51bf25\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public static void main(String[] args) {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51bf26\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 LinkedList&lt;String&gt;\u00a0 list = new LinkedList&lt;String&gt;();<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51bf27\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.add(&#8220;Test1&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51bf29\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.add(&#8220;Test1&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51bf2a\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.add(&#8220;Test2&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51bf2b\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.add(&#8220;Test3&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51bf2d\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.add(&#8220;Test4&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51bf2e\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51bf2f\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(&#8220;LinkedList before Inserting Element at the End\/Last&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51bf31\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(list);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51bf32\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51bf33\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.offerLast(&#8220;LastInsertedElement&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51bf35\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51bf36\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(&#8220;nLinkedList after Inserting Element at the End\/Last&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51bf37\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(list);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51bf39\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51bf3a\" style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51bf3b\" style=\"color: rgb(20, 237, 39);\">Output:<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51e1c1\" style=\"color: rgb(20, 237, 39);\">LinkedList before Inserting Element at the End\/Last<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51e1c3\" style=\"color: rgb(20, 237, 39);\">[Test1, Test1, Test2, Test3, Test4]<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51e1c4\" style=\"color: rgb(20, 237, 39);\">LinkedList after Inserting Element at the End\/Last<\/span><\/p>\n<p><span data-css=\"tve-u-17cec51bf40\" style=\"color: rgb(20, 237, 39);\">[Test1, Test1, Test2, Test3, Test4, LastInsertedElement]<\/span><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\" id=\"t-1636051989140\"><a class=\"tve-froala fr-basic\" 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\u00a0 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<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17cec5288d2\" style=\"\">\n<p><span data-css=\"tve-u-17cec52adce\" style=\"color: rgb(255, 255, 255);\">\/\/Pairwise Swap<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52add0\" style=\"color: rgb(255, 255, 255);\">public class LinkedList {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52add3\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 Node head;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52add4\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 class Node {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52add5\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int data;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52add7\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Node next;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52add9\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Node(int d)<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52adda\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52addb\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 data = d;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52addd\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 next = null;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52adde\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52addf\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ade1\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 void pairWiseSwap()<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ade2\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ade3\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Node temp = head;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ade5\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 while (temp != null &amp;&amp; temp.next != null) {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ade6\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int k = temp.data;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ade7\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 temp.data = temp.next.data;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ade8\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 temp.next.data = k;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52adea\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 temp = temp.next.next;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52adeb\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52aded\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52adee\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public void push(int new_data)<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52adef\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52adf1\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Node new_node = new Node(new_data);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52adf2\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 new_node.next = head;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52adf3\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 head = new_node;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52adf5\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52adf6\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 void print()<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52adf8\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52adf9\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Node temp = head;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52adfb\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 while (temp != null) {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52adfc\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.print(temp.data + &#8221; &#8220;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52adfd\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 temp = temp.next;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52adff\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ae00\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println();<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ae02\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ae03\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public static void main(String args[])<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ae04\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ae06\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 LinkedList list = new LinkedList();<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ae07\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.push(5);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ae08\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.push(4);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ae09\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.push(3);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ae0b\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.push(2);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ae0c\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.push(1);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ae0d\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(&#8220;Linked List before PairWise Swap &#8220;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ae0f\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.print();<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ae10\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.pairWiseSwap();<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ae11\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(&#8220;Linked List after PairWise Swap&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ae13\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.print();<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ae14\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ae15\" style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ae17\" style=\"color: rgb(46, 193, 73);\">Output:<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52d36a\" style=\"color: rgb(46, 193, 73);\">Linked List before PairWise Swap<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52d36b\" style=\"color: rgb(46, 193, 73);\">1 2 3 4 5<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52d36c\" style=\"color: rgb(46, 193, 73);\">Linked List after PairWise Swap<\/span><\/p>\n<p><span data-css=\"tve-u-17cec52ae1c\" style=\"color: rgb(46, 193, 73);\">2 1 4 3 5<\/span><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\" id=\"t-1636051989141\"><a class=\"tve-froala fr-basic\" name=\"_Toc82204603\" style=\"outline: none;\">5. Check if two arrays have same number of items and values<\/a><\/h3>\n<p><a class=\"tve-froala fr-basic\" 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<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17cec53c782\" style=\"\">\n<p><span data-css=\"tve-u-17cec53ebe7\" style=\"color: rgb(255, 255, 255);\">import java.util.Arrays;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ebe9\" style=\"color: rgb(255, 255, 255);\">public class Main {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ebeb\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public static void main(String args[]) {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ebec\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int[] array1 = { 1, 2, 3, 4 };<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ebee\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int[] array2 = { 2, 1, 4, 3 };<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ebef\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 boolean b = false;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ebf1\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (array1.length != array2.length) {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ebf3\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0b = false;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ebf5\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 } else {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ebf6\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Arrays.sort(array1);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ebf8\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Arrays.sort(array2);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ebf9\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 for(int i=0;i&lt;array1.length;i++) {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ebfa\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if(array1[i]!=array2[i]) {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ebfc\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 b=false;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ebfd\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 break;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ebfe\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ec00\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 b=true;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ec01\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ec03\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ec04\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (b)<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ec05\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(&#8220;Arrays are having same values&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ec07\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 else<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ec08\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(&#8220;Arrays are not having same values&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ec09\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ec0b\" style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ec0c\" style=\"color: rgb(55, 173, 34);\">Output:<\/span><\/p>\n<p><span data-css=\"tve-u-17cec53ec0d\" style=\"color: rgb(55, 173, 34);\">Arrays are having same values<\/span><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\" id=\"t-1636051989142\"><a class=\"tve-froala fr-basic\" 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<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17cec54c595\" style=\"\">\n<p><span data-css=\"tve-u-17cec54ee0e\" style=\"color: rgb(255, 255, 255);\">public class Main {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec54ee0f\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 \u00a0public static void main(String[] args){<\/span><\/p>\n<p><span data-css=\"tve-u-17cec54ee11\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0String string = &#8220;Rahul Shetty Academy is the best&#8221;;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec54ee12\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0String[] words = string.trim().replaceAll(&#8220;\\s+&#8221;, &#8221; &#8220;).split(&#8221; &#8220;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec54ee14\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 String shortest = words[0];<\/span><\/p>\n<p><span data-css=\"tve-u-17cec54ee15\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 String longest =\u00a0 words[0];<\/span><\/p>\n<p><span data-css=\"tve-u-17cec54ee16\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 for(String word : words){<\/span><\/p>\n<p><span data-css=\"tve-u-17cec54ee18\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0 if(word.length() &lt; shortest.length()){<\/span><\/p>\n<p><span data-css=\"tve-u-17cec54ee19\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 shortest = word;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec54ee1a\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec54ee1c\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0 if(word.length() &gt; longest.length()){<\/span><\/p>\n<p><span data-css=\"tve-u-17cec54ee1d\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 longest = word;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec54ee1e\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec54ee20\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec54ee21\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 System.out.println(&#8220;The Shortest Word = &#8220;+shortest);\u00a0\u00a0<\/span><\/p>\n<p><span data-css=\"tve-u-17cec54ee22\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 System.out.println(&#8220;The Longest Word = &#8220;+ longest);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec54ee24\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 \u00a0 }\u00a0<\/span><\/p>\n<p><span data-css=\"tve-u-17cec54ee25\" style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span data-css=\"tve-u-17cec54ee26\" style=\"color: rgb(36, 210, 36);\">Output:<\/span><\/p>\n<p><span data-css=\"tve-u-17cec550b2e\" style=\"color: rgb(36, 210, 36);\">The Shortest Word = is<\/span><\/p>\n<p><span data-css=\"tve-u-17cec54ee29\" style=\"color: rgb(36, 210, 36);\">The Longest Word = Academy<\/span><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\" id=\"t-1636051989143\"><a class=\"tve-froala fr-basic\" 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<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17cec55c05b\" style=\"\">\n<p><span data-css=\"tve-u-17cec55e10a\" style=\"color: rgb(255, 255, 255);\">class Main {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec55e10c\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 static boolean isPerfectSquare(int x)<\/span><\/p>\n<p><span data-css=\"tve-u-17cec55e10d\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec55e10f\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (x &gt;= 0) {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec55e110\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int sqrt = (int)Math.sqrt(x);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec55e111\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return ((sqrt*sqrt) == x);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec55e113\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec55e114\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return false;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec55e115\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec55e117\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public static void main(String[] args)<\/span><\/p>\n<p><span data-css=\"tve-u-17cec55e118\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec55e119\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int x = 8100;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec55e11b\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (isPerfectSquare(x))<\/span><\/p>\n<p><span data-css=\"tve-u-17cec55e11c\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.print(&#8220;Given Number is a Perfect Square&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec55e11d\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 else<\/span><\/p>\n<p><span data-css=\"tve-u-17cec55e11f\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.print(&#8220;Given Number is Not a Perfect Square&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec55e120\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec55e121\" style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span data-css=\"tve-u-17cec55e123\" style=\"color: rgb(34, 179, 42);\">Output:<\/span><\/p>\n<p><span data-css=\"tve-u-17cec55e124\" style=\"color: rgb(34, 179, 42);\">Given Number is a Perfect Square<\/span><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\" id=\"t-1636051989144\"><a class=\"tve-froala fr-basic\" 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<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17cec569acc\" style=\"\">\n<p><span data-css=\"tve-u-17cec56bc6c\" style=\"color: rgb(255, 255, 255);\">\/\/Abstraction<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc6e\" style=\"color: rgb(255, 255, 255);\">interface Car {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc6f\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 void printName();<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc71\" style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc72\" style=\"color: rgb(255, 255, 255);\">\/\/Inheritance<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc73\" style=\"color: rgb(255, 255, 255);\">class Ford {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc75\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 private String name; \/\/Encapsulation<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc76\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public String getName() {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc77\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return name;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc79\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc7a\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public void setName(String newName) {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc7b\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name = newName;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc7d\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc7e\" style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc7f\" style=\"color: rgb(255, 255, 255);\">class OneMore extends Ford implements Car{<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc81\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 @Override \/\/Overriding<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc82\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public void printName() {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc84\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(&#8220;Override Method Print &#8221; + super.getName());<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc85\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc86\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc88\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 \/\/Overloading<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc89\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public void printName(String string) {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc8a\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(&#8220;Overloaded Method Print &#8221; + string);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc8c\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc8d\" style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc8e\" style=\"color: rgb(255, 255, 255);\">class Main {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc90\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public static void main(String[] args) {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc91\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 OneMore object = new OneMore();<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc92\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 object.setName(&#8220;Eco Sport&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc94\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 object.printName();<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc95\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 object.printName(&#8220;Aspire&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc97\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc98\" style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc99\" style=\"color: rgb(39, 187, 24);\">Output:<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56e208\" style=\"color: rgb(39, 187, 24);\">Overloading Print Eco Sport<\/span><\/p>\n<p><span data-css=\"tve-u-17cec56bc9c\" style=\"color: rgb(39, 187, 24);\">Overloading Print Aspire<\/span><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\" id=\"t-1636051989145\"><a class=\"tve-froala fr-basic\" 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<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-17cec577da6\" style=\"\">\n<p><span data-css=\"tve-u-17cec57a5a8\" style=\"color: rgb(255, 255, 255);\">public class Main<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5aa\" style=\"color: rgb(255, 255, 255);\">{<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5ac\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 static int i,c,res;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5ad\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 static void length(String s)<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5af\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0 \u00a0{<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5b0\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 try<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5b2\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5b3\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 for(i=0,c=0;0&lt;=i;i++,c++)<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5b4\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 s.charAt(i);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5b6\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5b8\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 catch(StringIndexOutOfBoundsException e)<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5b9\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5ba\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 System.out.println(&#8220;&#8221;);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5bc\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.print(&#8220;The length of the string &#8220;&#8221;+s+&#8221;&#8221; is &#8221; +c);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5bd\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5bf\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5c0\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5c1\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 public static void main (String args[])<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5c3\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 {<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5c4\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 String string = &#8220;Rahul Shetty Academy&#8221;;<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5c6\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 length(string);<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5c7\" style=\"color: rgb(255, 255, 255);\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5c8\" style=\"color: rgb(255, 255, 255);\">}<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5ca\" style=\"color: rgb(33, 163, 60);\">Output:<\/span><\/p>\n<p><span data-css=\"tve-u-17cec57a5cb\" style=\"color: rgb(33, 163, 60);\">The length of the string &#8220;Rahul Shetty Academy&#8221; is 20<\/span><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h5 class=\"\" 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<\/div>\n<div class=\"thrv_wrapper thrv-styled_list\" data-icon-code=\"icon-angle-double-right-solid\">\n<ul class=\"tcb-styled-list\">\n<li class=\"thrv-styled-list-item\" data-css=\"tve-u-17d67373ebd\">\n<div class=\"tcb-styled-list-icon\">\n<div class=\"thrv_wrapper thrv_icon tve_no_drag tcb-no-delete tcb-no-clone tcb-no-save tcb-icon-inherit-style tcb-local-vars-root tcb-icon-display\" data-css=\"tve-u-17d675c92b3\" style=\"--tcb-local-color-icon:rgb(106, 107, 108); --tcb-local-color-var:rgb(106, 107, 108);\"><svg class=\"tcb-icon\" data-id=\"icon-angle-double-right-solid\" data-name=\"\" viewbox=\"0 0 448 512\"><path d=\"M224.3 273l-136 136c-9.4 9.4-24.6 9.4-33.9 0l-22.6-22.6c-9.4-9.4-9.4-24.6 0-33.9l96.4-96.4-96.4-96.4c-9.4-9.4-9.4-24.6 0-33.9L54.3 103c9.4-9.4 24.6-9.4 33.9 0l136 136c9.5 9.4 9.5 24.6.1 34zm192-34l-136-136c-9.4-9.4-24.6-9.4-33.9 0l-22.6 22.6c-9.4 9.4-9.4 24.6 0 33.9l96.4 96.4-96.4 96.4c-9.4 9.4-9.4 24.6 0 33.9l22.6 22.6c9.4 9.4 24.6 9.4 33.9 0l136-136c9.4-9.2 9.4-24.4 0-33.8z\"><\/path><\/svg><\/div>\n<\/div>\n<p><span class=\"thrv-advanced-inline-text tve_editable tcb-styled-list-icon-text tcb-no-delete tcb-no-save\" data-css=\"tve-u-17d67360b1c\"><a class=\"tve-froala fr-basic\" href=\"https:\/\/courses.rahulshettyacademy.com\/p\/sdet-test-architect-essentials-road-to-full-stack-qa\" style=\"outline: none;\" target=\"_blank\">SDET\/Test Architect Essentials -Road to Full stack QA<\/a><\/span><\/li>\n<li class=\"thrv-styled-list-item\" data-css=\"tve-u-17d67373ebd\">\n<div class=\"tcb-styled-list-icon\">\n<div class=\"thrv_wrapper thrv_icon tve_no_drag tcb-no-delete tcb-no-clone tcb-no-save tcb-icon-inherit-style tcb-icon-display\" data-css=\"tve-u-17d675c92b3\" style=\"--tcb-local-color-icon:rgb(106, 107, 108); --tcb-local-color-var:rgb(106, 107, 108);\"><svg class=\"tcb-icon\" data-id=\"icon-angle-double-right-solid\" data-name=\"\" viewbox=\"0 0 448 512\"><path d=\"M224.3 273l-136 136c-9.4 9.4-24.6 9.4-33.9 0l-22.6-22.6c-9.4-9.4-9.4-24.6 0-33.9l96.4-96.4-96.4-96.4c-9.4-9.4-9.4-24.6 0-33.9L54.3 103c9.4-9.4 24.6-9.4 33.9 0l136 136c9.5 9.4 9.5 24.6.1 34zm192-34l-136-136c-9.4-9.4-24.6-9.4-33.9 0l-22.6 22.6c-9.4 9.4-9.4 24.6 0 33.9l96.4 96.4-96.4 96.4c-9.4 9.4-9.4 24.6 0 33.9l22.6 22.6c9.4 9.4 24.6 9.4 33.9 0l136-136c9.4-9.2 9.4-24.4 0-33.8z\"><\/path><\/svg><\/div>\n<\/div>\n<p><span class=\"thrv-advanced-inline-text tve_editable tcb-styled-list-icon-text tcb-no-delete tcb-no-save\" data-css=\"tve-u-17d67360b1c\"><a class=\"tve-froala fr-basic\" href=\"https:\/\/courses.rahulshettyacademy.com\/p\/sdet-qa-automation-interview-kit-java-logic-programs\" style=\"outline: none;\" target=\"_blank\">SDET\/QA Automation Interview Kit + Java logic Programs<\/a><\/span><\/li>\n<\/ul>\n<\/div>\n<div class=\"tcb-clear\" data-css=\"tve-u-17d675d1f89\">\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box\" data-css=\"tve-u-17d675d1f8a\" data-ct=\"stylebox-8983\" data-ct-name=\"Tutorial: Note Box\" data-element-name=\"Styled Box\">\n<div class=\"tve-content-box-background\" data-css=\"tve-u-17d675d1f88\"><\/div>\n<div class=\"tve-cb tve_empty_dropzone\" data-css=\"tve-u-17d675d1f86\">\n<div class=\"thrv_wrapper thrv_text_element tve_empty_dropzone\" data-css=\"tve-u-17d675d1f87\">\n<h4 class=\"\"><em><strong>A Quick Note<\/strong><\/em><\/h4>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element tve_empty_dropzone\">\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<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\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 class=\"tve-froala fr-basic\" data-css=\"tve-u-17d7230a731\" href=\"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2021\/07\/31\/top-30-api-testing-interview-questions-and-answers\/\" style=\"outline: none;\" target=\"_blank\">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<\/div>\n<\/div>\n<\/div>\n<div class=\"tcb_flag\" style=\"display: none\"><\/div>\n<\/section>\n<p><\/body><\/html><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Table of Contents 1. Write a program to sort ArrayList using Comparable and Comparator 2. I have arrayList like [Test1, Test2, Test3, Test4, Test5] Write a Program to replace the &#8220;Test2&#8221; with string &#8220;ReplacedTest&#8221; 3. Write a Java program to insert the specified element at the end of a linked list 4. Write a program [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,5],"tags":[],"class_list":["post-1305","post","type-post","status-publish","format-standard","hentry","category-interview-questions","category-java","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":0,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1305\/revisions"}],"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}]}}