How to sort a list alphabetically in Java

1 Answer

0 votes
import java.util.List;
import java.util.Arrays;
import java.util.Collections;

public class MyClass {

    public static void main(String args[]) {   
        
        List<String> list = Arrays.asList("java", "c", "c#", "python", "c++");
        
        Collections.sort(list);
 
        System.out.println(list);
    }
}
 
 
    
    
    
/*
run:
    
[c, c#, c++, java, python]

*/

 



answered Nov 9, 2023 by avibootz

Related questions

2 answers 222 views
1 answer 139 views
1 answer 164 views
1 answer 232 views
1 answer 152 views
4 answers 406 views
...