ArrayList in Java can sort output with a~z letters? __java

Source: Internet
Author: User

ArrayList in Q:java can be sorted with a~z alphabetical output.

A:collections.sort (list); This is sorted by nature and is sorted alphabetically

A:import java.util.ArrayList;
Import java.util.Collections;
public class app{
public static void Main (String args[]) {
Arraylist<character> al=new arraylist<character> ();
for (int i=0;i<20;i++) {
Al.add ((char) (' a ' + (int) (Math.random () *26));
}
System.out.println (AL);
Collections.sort (AL);
System.out.println (AL);
}
}

A:list are unordered, repeatable collections, and naturally there are no sorting methods.

A:list does not have its own sorting method, only set has its own sorting method, but it can be sorted by collections in the sort method of a set.

A:list sorting method without self-band
But you can sort by arrays.sort () first.
And then build the list.
List minn= arrays.aslist (score);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.