java-deep copy/Shallow copy Comparator

Source: Internet
Author: User

Only the underlying built-in element = deep copy (string not) you define the class if you need a deep copy, to rewrite Cloneable's Clone method if the inheritance relationship, the parent class will also be rewritten. Http://www.cnblogs.com/yxnchinahlj/archive/2010/09/20/1831615.html① Why do we have to call Super.clone () when we override the Clone () method of object in a derived class? At run time, Clone () in object identifies which object you want to copy, then allocates space for the object, replicates the object, and copies the contents of the original object one by one into the storage space of the new object.  
②the Clone () method that inherits from the Java.lang.Object class is shallow copy.
Http://bbs.csdn.net/topics/360077763http://zhidao.baidu.com/link?url=UktuJvqqUbe3BJcy4nlNoee09gZfGBIB_ Sdvvrcbfjn8hdodswcbi8onllcdqp4cmfvm9wvz3xfvnxn3bz_foa

The comparator wants to override the Compare method in the comparator interface import Java.io.*;import Java.net.*;import java.util.*;
public class test{public static void Main (String args[]) throws exception{treemap<string,integer> mm=new treemap& Lt    String,integer> (New Comparator () {public int compare (Object A,object b) {string aa= (string) A;    String bb= (string) b;   return Bb.compareto (AA);  }  });  Mm.put (New String ("a"), new Integer (23));  Mm.put ("B", New Integer (31));  Set<map.entry<string,integer>> Set=mm.entryset ();  SYSTEM.OUT.PRINTLN (set); System.out.println (Mm.keyset ()); }}

java-deep copy/Shallow copy Comparator

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.