Object de-weight principle in Java list

Source: Internet
Author: User

/******************************************************************************* * * Copyright (c) Weaver Info Tech  Co. LTD * * Sessioninfo * * App.backend.model.SessionInfo.java * todo:file description or class description. *  * @author: Administrator *@since: 2014-5-26 *@version: 1.0.0 * * @changeLogs: * 1.0.0:first created this class. *  ******************************************************************************/    Importjava.io.Serializable; /**  * @authorAdministrator **/@SuppressWarnings ("Serial")   Public classSessioninfoImplementsserializable{Private intID; PrivateString URL;  Public intgetId () {returnID; }       Public voidSetId (intID) { This. ID =ID; }         PublicString GetUrl () {returnURL; } @Override PublicString toString () {return"sessioninfo{" + "id=" + ID + ", url= '" + url + ' \ ' + '} '; }     Public voidseturl (String url) { This. url =URL; }        /*(non-javadoc) * @see Java.lang.object#hashcode ()*/@Override Public inthashcode () {returnID; }        /*(non-javadoc) * @see java.lang.object#equals (java.lang.Object)*/@Override Public Booleanequals (Object o) {if(O = =NULL) {              return false; } Else {              if(O.getclass ()! = This. GetClass ()) {                  return false; } Else {                  FinalSessioninfo s =(Sessioninfo) o; returnS.id = = This. ID; }          }      }  }  

ImportJava.util.*; Public classHashcodetest { Public Static voidMain (string[] args) {sessioninfo sessionInfo1=NewSessioninfo (); Sessioninfo SessionInfo2=NewSessioninfo (); Sessioninfo1.setid (1); Sessioninfo2.setid (1); Sessioninfo1.seturl ("Test"); Sessioninfo2.seturl ("Test"); Sessioninfo Msessioninfo=NULL;//entity class objectSet<sessioninfo> sessionlist =NewHashset<sessioninfo> ();//declaring a set collection object        Finallist<sessioninfo> list =NewArraylist<sessioninfo> ();//declaring a list collection objectSessionlist.add (SESSIONINFO1);//to add an object to the Set collectionSessionlist.add (SessionInfo2);//to add an object to the Set collectionList.addall (sessionlist);//to add data to the List collection Object         for(inti = 0; I < list.size (); i++) {System.out.println (List.get (i)); }    }}  

Object de-weight principle in Java list

Related Article

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.