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 ());}}