SlideShare a Scribd company logo
1 of 3
Download to read offline
(Sort ArrayList) Write the following method that sorts an ArrayList: public static >
void sort(ArrayList list
JAVA
Solution
import java.util.ArrayList;
/**
* @author
*
*/
public class GenericSort {
/**
* method to sort the list
*
* @param list
*/
public static > void sort(ArrayList list) {
Object currentMax;
int currentMaxIndex;
for (int i = list.size() - 1; i >= 1; i--) {
// Find the maximum in the list[0..i]
currentMax = list.get(i);
currentMaxIndex = i;
for (int j = i - 1; j >= 0; j--) {
if (((Comparable) currentMax).compareTo(list.get(j)) < 0) {
currentMax = list.get(j);
currentMaxIndex = j;
}
}
// Swap list[i] with list[currentMaxIndex] if necessary;
if (currentMaxIndex != i) {
list.set(currentMaxIndex, list.get(i));
list.set(i, (E) currentMax);
}
}
}
/**
* @param args
*/
public static void main(String[] args) {
Integer[] intArray = { new Integer(2), new Integer(4), new Integer(3) };
// Create a String List
ArrayList stringList = new ArrayList();
stringList.add("Srinivas");
stringList.add("Pavan");
stringList.add("Kishore");
stringList.add("Rajesh");
stringList.add("Charkri");
// Create a int List
ArrayList intList = new ArrayList();
intList.add(20);
intList.add(30);
intList.add(10);
intList.add(40);
intList.add(90);
intList.add(50);
System.out.println("Before sorting :");
System.out.println(stringList);
System.out.println(intList);
// Sort the arrays
sort(stringList);
sort(intList);
System.out.println("After sorting :");
System.out.println(stringList);
System.out.println(intList);
}
}
OUTPUT:
Before sorting :
[Srinivas, Pavan, Kishore, Rajesh, Charkri]
[20, 30, 10, 40, 90, 50]
After sorting :
[Charkri, Kishore, Pavan, Rajesh, Srinivas]
[10, 20, 30, 40, 50, 90]

More Related Content

Similar to (Sort ArrayList) Write the following method that sorts an ArrayList.pdf

2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
arshin9
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdf
seoagam1
 
Implement the ListArray ADT-Implement the following operations.pdf
Implement the ListArray ADT-Implement the following operations.pdfImplement the ListArray ADT-Implement the following operations.pdf
Implement the ListArray ADT-Implement the following operations.pdf
petercoiffeur18
 
Write a java class LIST that outputsmainpublic class Ass.pdf
Write a java class LIST that outputsmainpublic class Ass.pdfWrite a java class LIST that outputsmainpublic class Ass.pdf
Write a java class LIST that outputsmainpublic class Ass.pdf
ebrahimbadushata00
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
annaelctronics
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
ravikapoorindia
 
you will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdfyou will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdf
info335653
 
I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdf
fonecomp
 
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdf
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdfSorting Questions (JAVA)See attached classes below.Attached Clas.pdf
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdf
akritigallery
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
xlynettalampleyxc
 
Please create the appropriate JUnit test cases to thoroughly.pdf
Please create the appropriate JUnit test cases to thoroughly.pdfPlease create the appropriate JUnit test cases to thoroughly.pdf
Please create the appropriate JUnit test cases to thoroughly.pdf
kitty811
 
import static org.junit.Assert.;import java.util.Arrays; import.pdf
import static org.junit.Assert.;import java.util.Arrays; import.pdfimport static org.junit.Assert.;import java.util.Arrays; import.pdf
import static org.junit.Assert.;import java.util.Arrays; import.pdf
sudheerforce
 

Similar to (Sort ArrayList) Write the following method that sorts an ArrayList.pdf (20)

Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
 
In Java code, implement the HeapSort algorithm. Your function must t.pdf
In Java code, implement the HeapSort algorithm. Your function must t.pdfIn Java code, implement the HeapSort algorithm. Your function must t.pdf
In Java code, implement the HeapSort algorithm. Your function must t.pdf
 
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Array list
Array listArray list
Array list
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdf
 
Collection and framework
Collection and frameworkCollection and framework
Collection and framework
 
Implement the ListArray ADT-Implement the following operations.pdf
Implement the ListArray ADT-Implement the following operations.pdfImplement the ListArray ADT-Implement the following operations.pdf
Implement the ListArray ADT-Implement the following operations.pdf
 
Write a java class LIST that outputsmainpublic class Ass.pdf
Write a java class LIST that outputsmainpublic class Ass.pdfWrite a java class LIST that outputsmainpublic class Ass.pdf
Write a java class LIST that outputsmainpublic class Ass.pdf
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
 
Array list (java platform se 8 )
Array list (java platform se 8 )Array list (java platform se 8 )
Array list (java platform se 8 )
 
Selection sort
Selection sortSelection sort
Selection sort
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
you will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdfyou will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdf
 
I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdf
 
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdf
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdfSorting Questions (JAVA)See attached classes below.Attached Clas.pdf
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdf
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
 
Please create the appropriate JUnit test cases to thoroughly.pdf
Please create the appropriate JUnit test cases to thoroughly.pdfPlease create the appropriate JUnit test cases to thoroughly.pdf
Please create the appropriate JUnit test cases to thoroughly.pdf
 
import static org.junit.Assert.;import java.util.Arrays; import.pdf
import static org.junit.Assert.;import java.util.Arrays; import.pdfimport static org.junit.Assert.;import java.util.Arrays; import.pdf
import static org.junit.Assert.;import java.util.Arrays; import.pdf
 
Java10 Collections and Information
Java10 Collections and InformationJava10 Collections and Information
Java10 Collections and Information
 

More from alokkesh

LinearPerson.javaPlease help me the JAVA programPlease provide t.pdf
LinearPerson.javaPlease help me the JAVA programPlease provide t.pdfLinearPerson.javaPlease help me the JAVA programPlease provide t.pdf
LinearPerson.javaPlease help me the JAVA programPlease provide t.pdf
alokkesh
 
Flag this QuestionQuestion 12 1 ptsPolytene chromosomes arise fr.pdf
Flag this QuestionQuestion 12 1 ptsPolytene chromosomes arise fr.pdfFlag this QuestionQuestion 12 1 ptsPolytene chromosomes arise fr.pdf
Flag this QuestionQuestion 12 1 ptsPolytene chromosomes arise fr.pdf
alokkesh
 
For our discussion question, we focus on recent trends in security t.pdf
For our discussion question, we focus on recent trends in security t.pdfFor our discussion question, we focus on recent trends in security t.pdf
For our discussion question, we focus on recent trends in security t.pdf
alokkesh
 
Fill in the blanksMicronutrients this refers to a sub-category o.pdf
Fill in the blanksMicronutrients this refers to a sub-category o.pdfFill in the blanksMicronutrients this refers to a sub-category o.pdf
Fill in the blanksMicronutrients this refers to a sub-category o.pdf
alokkesh
 
ecourses.pvamu.edu Help English United States en us) Question4 Ma.pdf
ecourses.pvamu.edu Help English United States en us) Question4 Ma.pdfecourses.pvamu.edu Help English United States en us) Question4 Ma.pdf
ecourses.pvamu.edu Help English United States en us) Question4 Ma.pdf
alokkesh
 
DiARTHROIDAL joints can be classified based on their characteristics.pdf
DiARTHROIDAL joints can be classified based on their characteristics.pdfDiARTHROIDAL joints can be classified based on their characteristics.pdf
DiARTHROIDAL joints can be classified based on their characteristics.pdf
alokkesh
 
Cite the distinction between graphite and carbon. Carbon and graphit.pdf
Cite the distinction between graphite and carbon.  Carbon and graphit.pdfCite the distinction between graphite and carbon.  Carbon and graphit.pdf
Cite the distinction between graphite and carbon. Carbon and graphit.pdf
alokkesh
 

More from alokkesh (20)

most extra cellular environments contain a high concentration of sod.pdf
most extra cellular environments contain a high concentration of sod.pdfmost extra cellular environments contain a high concentration of sod.pdf
most extra cellular environments contain a high concentration of sod.pdf
 
Let X be the prive of a meal at a local diner( X = $8,$10,and $12) a.pdf
Let X be the prive of a meal at a local diner( X = $8,$10,and $12) a.pdfLet X be the prive of a meal at a local diner( X = $8,$10,and $12) a.pdf
Let X be the prive of a meal at a local diner( X = $8,$10,and $12) a.pdf
 
LinearPerson.javaPlease help me the JAVA programPlease provide t.pdf
LinearPerson.javaPlease help me the JAVA programPlease provide t.pdfLinearPerson.javaPlease help me the JAVA programPlease provide t.pdf
LinearPerson.javaPlease help me the JAVA programPlease provide t.pdf
 
is acute or chronic exposure to heptachlor more of a danger to human.pdf
is acute or chronic exposure to heptachlor more of a danger to human.pdfis acute or chronic exposure to heptachlor more of a danger to human.pdf
is acute or chronic exposure to heptachlor more of a danger to human.pdf
 
In “Intellectual Property and the Information Age,” Richard T. De Ge.pdf
In “Intellectual Property and the Information Age,” Richard T. De Ge.pdfIn “Intellectual Property and the Information Age,” Richard T. De Ge.pdf
In “Intellectual Property and the Information Age,” Richard T. De Ge.pdf
 
How does horizontal transfer affect the evolution of anti-biotic res.pdf
How does horizontal transfer affect the evolution of anti-biotic res.pdfHow does horizontal transfer affect the evolution of anti-biotic res.pdf
How does horizontal transfer affect the evolution of anti-biotic res.pdf
 
Flag this QuestionQuestion 12 1 ptsPolytene chromosomes arise fr.pdf
Flag this QuestionQuestion 12 1 ptsPolytene chromosomes arise fr.pdfFlag this QuestionQuestion 12 1 ptsPolytene chromosomes arise fr.pdf
Flag this QuestionQuestion 12 1 ptsPolytene chromosomes arise fr.pdf
 
Genetic drift tends to genetic variation wITHIN small populations, an.pdf
Genetic drift tends to genetic variation wITHIN small populations, an.pdfGenetic drift tends to genetic variation wITHIN small populations, an.pdf
Genetic drift tends to genetic variation wITHIN small populations, an.pdf
 
For our discussion question, we focus on recent trends in security t.pdf
For our discussion question, we focus on recent trends in security t.pdfFor our discussion question, we focus on recent trends in security t.pdf
For our discussion question, we focus on recent trends in security t.pdf
 
Fill in the blanksMicronutrients this refers to a sub-category o.pdf
Fill in the blanksMicronutrients this refers to a sub-category o.pdfFill in the blanksMicronutrients this refers to a sub-category o.pdf
Fill in the blanksMicronutrients this refers to a sub-category o.pdf
 
ecourses.pvamu.edu Help English United States en us) Question4 Ma.pdf
ecourses.pvamu.edu Help English United States en us) Question4 Ma.pdfecourses.pvamu.edu Help English United States en us) Question4 Ma.pdf
ecourses.pvamu.edu Help English United States en us) Question4 Ma.pdf
 
Explain why several versions of nMOS transistor models and pMOS trans.pdf
Explain why several versions of nMOS transistor models and pMOS trans.pdfExplain why several versions of nMOS transistor models and pMOS trans.pdf
Explain why several versions of nMOS transistor models and pMOS trans.pdf
 
Explain How Culture influences the way mangers perform their four ma.pdf
Explain How Culture influences the way mangers perform their four ma.pdfExplain How Culture influences the way mangers perform their four ma.pdf
Explain How Culture influences the way mangers perform their four ma.pdf
 
Describeillustrate the construction used by the ancient Indians to s.pdf
Describeillustrate the construction used by the ancient Indians to s.pdfDescribeillustrate the construction used by the ancient Indians to s.pdf
Describeillustrate the construction used by the ancient Indians to s.pdf
 
Describe the factors that contribute to a membrane potential. What i.pdf
Describe the factors that contribute to a membrane potential. What i.pdfDescribe the factors that contribute to a membrane potential. What i.pdf
Describe the factors that contribute to a membrane potential. What i.pdf
 
DiARTHROIDAL joints can be classified based on their characteristics.pdf
DiARTHROIDAL joints can be classified based on their characteristics.pdfDiARTHROIDAL joints can be classified based on their characteristics.pdf
DiARTHROIDAL joints can be classified based on their characteristics.pdf
 
Define and explain chemical equilibrium Include the defenition o.pdf
Define and explain chemical equilibrium Include the defenition o.pdfDefine and explain chemical equilibrium Include the defenition o.pdf
Define and explain chemical equilibrium Include the defenition o.pdf
 
Cite the distinction between graphite and carbon. Carbon and graphit.pdf
Cite the distinction between graphite and carbon.  Carbon and graphit.pdfCite the distinction between graphite and carbon.  Carbon and graphit.pdf
Cite the distinction between graphite and carbon. Carbon and graphit.pdf
 
C Language ProblemPlease Explain If int n1 = 5, and int d1 = 2, wh.pdf
C Language ProblemPlease Explain If int n1 = 5, and int d1 = 2, wh.pdfC Language ProblemPlease Explain If int n1 = 5, and int d1 = 2, wh.pdf
C Language ProblemPlease Explain If int n1 = 5, and int d1 = 2, wh.pdf
 
According to Cisco design theory for a fully switched network, hosts.pdf
According to Cisco design theory for a fully switched network, hosts.pdfAccording to Cisco design theory for a fully switched network, hosts.pdf
According to Cisco design theory for a fully switched network, hosts.pdf
 

Recently uploaded

QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
 

Recently uploaded (20)

QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 

(Sort ArrayList) Write the following method that sorts an ArrayList.pdf

  • 1. (Sort ArrayList) Write the following method that sorts an ArrayList: public static > void sort(ArrayList list JAVA Solution import java.util.ArrayList; /** * @author * */ public class GenericSort { /** * method to sort the list * * @param list */ public static > void sort(ArrayList list) { Object currentMax; int currentMaxIndex; for (int i = list.size() - 1; i >= 1; i--) { // Find the maximum in the list[0..i] currentMax = list.get(i); currentMaxIndex = i; for (int j = i - 1; j >= 0; j--) { if (((Comparable) currentMax).compareTo(list.get(j)) < 0) { currentMax = list.get(j); currentMaxIndex = j; } } // Swap list[i] with list[currentMaxIndex] if necessary; if (currentMaxIndex != i) { list.set(currentMaxIndex, list.get(i)); list.set(i, (E) currentMax); }
  • 2. } } /** * @param args */ public static void main(String[] args) { Integer[] intArray = { new Integer(2), new Integer(4), new Integer(3) }; // Create a String List ArrayList stringList = new ArrayList(); stringList.add("Srinivas"); stringList.add("Pavan"); stringList.add("Kishore"); stringList.add("Rajesh"); stringList.add("Charkri"); // Create a int List ArrayList intList = new ArrayList(); intList.add(20); intList.add(30); intList.add(10); intList.add(40); intList.add(90); intList.add(50); System.out.println("Before sorting :"); System.out.println(stringList); System.out.println(intList); // Sort the arrays sort(stringList); sort(intList); System.out.println("After sorting :"); System.out.println(stringList); System.out.println(intList); } } OUTPUT: Before sorting : [Srinivas, Pavan, Kishore, Rajesh, Charkri]
  • 3. [20, 30, 10, 40, 90, 50] After sorting : [Charkri, Kishore, Pavan, Rajesh, Srinivas] [10, 20, 30, 40, 50, 90]