“So sortieren Sie eine Liste in Java” Code-Antworten

Java -Sortierliste

List<String> entries = new ArrayList<>();
entries = entries.stream().sorted().collect(Collectors.toList());
Adorable Addax

Java -Sortierliste

List<String> list = new ArrayList<>();
java.util.Collections.sort(list); // sorts lexicographically
PutinsRightNut

Java -Liste sortieren Sie mit Sort () Methode

import java.util.*;
 
public class Main {  
public static void main(String[] args) {  
        List<String> list= new ArrayList<>(); 
        
        list.add("Apple");  
        list.add("Mango");  
        list.add("Banana");  
     
        System.out.println("List : "+list);  
        //will sort the string acc to the alphabets  
        Collections.sort(list);  
        System.out.println("Sorted List : "+list);  
    }  
}
Outrageous Ostrich

Java -Sortierliste


Collections.sort(testList);
Collections.reverse(testList);

Homeless Hyena

Sortierliste in Java

Collections.sort(al);
Light Lark

So sortieren Sie eine Liste in Java

List<String> elements = new ArrayList<>();
// The list of strings will be sorted lexicographically
elements.sort();
// You can also implement a custom comparator
Comparator<String> comp = new Comparator<String>(){
   @Override
   public int compare(final String s1,String s2) {
     //TODO return 1 if rhs should be before lhs 
     //     return -1 if lhs should be before rhs
     //     return 0 otherwise (meaning the order stays the same)
     }
 };
elements.sort(comp);
Brens

Ähnliche Antworten wie “So sortieren Sie eine Liste in Java”

Fragen ähnlich wie “So sortieren Sie eine Liste in Java”

Weitere verwandte Antworten zu “So sortieren Sie eine Liste in Java” auf Java

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen