目录

Object clone()

描述 (Description)

clone()方法用于返回此TreeMap实例的浅表副本。但是不会克隆键和值本身。

声明 (Declaration)

以下是java.util.TreeMap.clone()方法的声明。

public Object clone()

参数 (Parameters)

NA

返回值 (Return Value)

方法调用返回此映射的浅表副本。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.util.TreeMap.clone()方法的用法。

package com.iowiki;
import java.util.*;
public class TreeMapDemo {
   public static void main(String[] args) {
      // creating tree map 
      TreeMap<Integer, String> treemap = new TreeMap<Integer, String>();
      TreeMap<Integer, String> treemapclone = new TreeMap<Integer, String>();
      // populating tree map
      treemap.put(2, "two");
      treemap.put(1, "one");
      treemap.put(3, "three");
      treemap.put(6, "six");
      treemap.put(5, "five");
      // cloning tree map
      System.out.println("Cloning tree map");
      treemapclone = (TreeMap)treemap.clone();
      System.out.println("Original map: "+ treemap);
      System.out.println("Cloned map: "+ treemapclone);
   }    
}

让我们编译并运行上面的程序,这将产生以下结果。

Cloning tree map
Original map: {1=one, 2=two, 3=three, 5=five, 6=six}
Cloned map: {1=one, 2=two, 3=three, 5=five, 6=six}
↑回到顶部↑
WIKI教程 @2018