How can I Sort an ArrayList in Java

0 votes
I want to sort an ArrayList

List alist<Float>=new ArrayList();

alist.add(2.3);

alist.add(4.2);

alist.add(0.5);
Apr 23, 2018 in Java by developer_1
• 3,350 points
860 views

1 answer to this question.

0 votes

You can sort the ArrayList in 2 steps:

  1.  import java.util.collections;
  2.  Collections.sort(alist);

answered Apr 23, 2018 by sharth
• 3,370 points

Related Questions In Java

0 votes
2 answers
0 votes
3 answers

How can I add new elements to an Array in Java

String[] source = new String[] { "a", ...READ MORE

answered Sep 19, 2018 in Java by Sushmita
• 6,920 points
13,190 views
+1 vote
6 answers

How can I separate the digits of an int number in Java?

You can also have a look here: To ...READ MORE

answered Dec 9, 2020 in Java by Roshni
• 10,480 points
209,893 views
0 votes
2 answers

How can I sort values of a Map in Java using its key

Assuming TreeMap is not good for you ...READ MORE

answered Oct 10, 2018 in Java by Sushmita
• 6,920 points
1,205 views
0 votes
1 answer

Sorting an ArrayList in Java

You can easily do this by simply ...READ MORE

answered May 5, 2018 in Java by geek.erkami
• 2,680 points
2,179 views
0 votes
1 answer

Sort ArrayList of custom Objects by property

Since Date implements Comparable, it has a compareTo method just like String does. So your ...READ MORE

answered Dec 22, 2020 in Java by Gitika
• 65,770 points
1,487 views
0 votes
2 answers

One line initialization of an ArrayList object in Java

In Java 8 or earlier: List<String> string = ...READ MORE

answered Jul 26, 2018 in Java by samarth295
• 2,220 points
4,757 views
0 votes
2 answers

How to convert an array to arraylist?

In Java 9 you can use: List<String> list= List.of("Hello", "World", ...READ MORE

answered Aug 1, 2018 in Java by samarth295
• 2,220 points
1,050 views
0 votes
2 answers

How can I convert a String variable to a primitive int in Java

 Here are two ways illustrating this: Integer x ...READ MORE

answered Aug 20, 2019 in Java by Sirajul
• 59,230 points
2,310 views
0 votes
2 answers

How can I convert byte array into hex string in Java?

public static String byteArrayToHex(byte[] a) { ...READ MORE

answered Aug 29, 2019 in Java by Sirajul
• 59,230 points
2,919 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP