Java set sorting

Source: Internet
Author: User

How can I sort a List set in java? The front-end time encounters a structure sorting List similar to this in the work. > What about sorting by a key value in Map? The collection is generated as follows:

Public void sortList () {List
 
  
> List = new ArrayList
  
   
>>(); Int group = 0; for (int I = 0; I <10; I ++) {List
   
    
> TempList = new ArrayList
    
     
> (); Group = new Random (). nextInt (45); for (int j = 0; j <2; j ++) {Map
     
      
Map = new HashMap
      
        (); Map. put ("group", group + ""); tempList. add (map);} list. add (tempList) ;}for (int I = 0; I
       
         The group sequence is as follows:
        
group ==43group ==25group ==28group ==32group ==19group ==20group ==25group ==21group ==24group ==36
The sorting function is:
Public List
         
          
> SortResList (List
          
           
> List) {if (list! = Null & list. size ()> 0) {for (int I = 0; I
           
            
This sorting function uses the idea of Bubble sorting. The main idea is to call API Collections. swap (List
            List, int I, int j!
            
The sorted result is: after sort, group = 3 group = 9 group = 9 group = 10 group = 12 group = 23 group = 24 group = 36 group = 43 group = 44
------- The road is long, and I will go up and down



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.