JAVA-deep copy/Light copy comparator, java-copy

Source: Internet
Author: User

JAVA-deep copy/Light copy comparator, java-copy
Only the basic built-in element = is used for deep copy (the String is not). If you need to copy the class deeply, you need to rewrite the Clone method of Cloneable. If it is an inheritance relationship, the parent class must also be overwritten. When using the lift () method, must we call super. clone? During runtime, the Object clone () identifies the Object you want to copy, allocates space for the Object, and copies the Object, copy the content of the original object to the bucket of the new object one by one.
② The clone () method inherited from the java. lang. Object class is a shortest copy.
Http://bbs.csdn.net/topics/360077763http://zhidao.baidu.com/link? Url = Response

The Comparator needs to override the compare method import java. io. * In the Comparator interface; import java.net. *; import java. util .*;
Public class Test {public static void main (String args []) throws Exception {TreeMap <String, Integer> mm = new TreeMap <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 ());}}

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.