Java is arranged in reverse order by object attribute values (for example)

Source: Internet
Author: User

The list of retrieved Javabean is arranged in reverse order by recheckerrorlen (the attribute of this bean) (if you want to arrange it in the forward order, you only need to change the position of the subtrahend and subtrahend in the compareto method)

Note: Implements comparable is required

Public class userrecheckstaticts implements serializable, comparable <userrecheckstaticts>
{
Private Static final long serialversionuid = 1l;
 
Private string userip;
Private int rechecklen;
Private int recheckerrorlen;
Private int laststatus;

Private string statusstatictsstr;
Public String getuserip (){
Return userip;
}
Public void setuserip (string userip ){
This. userip = userip;
}
Public int getrechecklen (){
Return rechecklen;
}
Public void setrechecklen (INT rechecklen ){
This. rechecklen = rechecklen;
}
Public int getrecheckerrorlen (){
Return recheckerrorlen;
}
Public void setrecheckerrorlen (INT recheckerrorlen ){
This. recheckerrorlen = recheckerrorlen;
}
Public int getlaststatus (){
Return laststatus;
}
Public void setlaststatus (INT laststatus ){
This. laststatus = laststatus;
}
Public String getstatusstatictsstr (){
Return statusstatictsstr;
}
Public void setstatusstatictsstr (string statusstatictsstr ){
This. statusstatictsstr = statusstatictsstr;
}
Public int compareto (userrecheckstaticts O ){
Return O. recheckerrorlen-This. recheckerrorlen;
}
}

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.