Mengurutkan Data ArrayList Descending di Java

import java.util.ArrayList;
import java.util.Collections;

public class ArrayListTestSorting{
public static void main(String args[]){
ArrayList<String> arraylist = new ArrayList<String>();
arraylist.add(“AA”);
arraylist.add(“ZZ”);
arraylist.add(“CC”);
arraylist.add(“FF”);

/*Unsorted List: ArrayList content before sorting*/
System.out.println(“Before Sorting:”);
for(String str: arraylist){
System.out.println(str);
}

/* Sorting in decreasing order*/
Collections.sort(arraylist, Collections.reverseOrder());

/* Sorted List in reverse order*/
System.out.println(“ArrayList in descending order:”);
for(String str: arraylist){
System.out.println(str);
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s