Java List sorting

Source: Internet
Author: User

1. Java encapsulation class

Student. java:

/*** @ Title: Student. java * @ Package: com. you. data * @ Description: * @ Author: youhaidong * @ date: 10:33:20, January 1, March 17, 2014 * @ Version V1.2.3 */package com. you. data; import java. util. comparator;/*** @ class Name: Student * @ Description: * @ Author: Administrator * @ date: 10:33:20, January 1, March 17, 2014 */public class Student implements Comparator
 
  
{/*** ID */private Long id;/*** student ID */private int stuNo;/*** name */private String stuName; /*** age */private int age;/*** Gender */private String sex;/*** @ Description: get Method * @ date: march 17, 2014 10:36:11 * @ return the id */public Long getId () {return id;}/*** @ Description: set Method * @ date: march 17, 2014 10:36:11 * @ param id the id to set */public void setId (Long id) {this. id = id;}/*** @ Description: get Method * @ date: 10:36:11, January 1, March 17, 2014 * @ return the stuNo */public int getStuNo () {return stuNo ;} /*** @ Description: set Method * @ date: March 17, 2014 10:36:11 * @ param stuNo the stuNo to set */public void setStuNo (int stuNo) {this. stuNo = stuNo;}/*** @ Description: get Method * @ date: 10:36:11, January 1, March 17, 2014 * @ return the stuName */public String getStuName () {return stuName ;} /*** @ Description: set Method * @ date: March 17, 2014 10:36:11 * @ param stuName the stuName to set */public void setStuName (String stuName) {this. stuName = stuName;}/*** @ Description: get Method * @ date: 10:36:11, January 1, March 17, 2014 * @ return the age */public int getAge () {return age ;} /*** @ Description: set Method * @ date: March 17, 2014 10:36:11 * @ param age the age to set */public void setAge (int age) {this. age = age;}/*** @ Description: get Method * @ date: 10:36:11, January 1, March 17, 2014 * @ return the sex */public String getSex () {return sex ;} /*** @ Description: set Method * @ date: March 17, 2014 10:36:11 * @ param sex the sex to set */public void setSex (String sex) {this. sex = sex;}/*** (non-Javadoc )*
  

Title: compare

*

Description:

* @ Param o1 * @ param o2 * @ return * @ see java. util. comparator # compare (java. lang. object, java. lang. object) * March 17, 2014 10:33:20 */@ Overridepublic int compare (Student o1, Student o2) {Student stu1 = (Student) o1; Student stu2 = (Student) o2; if (null! = Stu1 & null! = Stu2) {if (stu1.getStuNo () <stu2.getStuNo () {return 1 ;}else {return 0 ;}} return-1 ;}}


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.