java.util.Collections.sort()のサンプル

サンプルコード:
package study;
import java.util.ArrayList;
import java.util.Collections;

public class CollectionDemo {

public static void main(String[] args) {
// Create a list of strings
ArrayList<String> cft = new ArrayList<String>();
cft.add(“Geeks");
cft.add(“Dear");
cft.add(“Company");
cft.add(“Reuser");
cft.add(“Employee info");

/*
* Collections.sort method is sorting the
* elements of ArrayList in ascending order.
*/
Collections.sort(cft);

// Let us print the sorted list
System.out.println(“List after the use of" + " Collection.sort() :\n" + cft);

}
結果
List after the use of Collection.sort() :
[Company, Dear, Employee info, Geeks, Reuser]

Java

Posted by arkgame