爪哇。util。枚举集。Java中的clone()方法用于返回现有或此集合的浅拷贝。
null
语法:
Enum_Set_2 = Enum_Set_1.clone()
参数: 该方法不采用任何参数。
返回值: 该方法不返回任何值。
下面的程序说明了Java的工作原理。util。枚举集。clone()方法: 项目1:
// Java program to demonstrate clone() method import java.util.*; // Creating an enum of GFG type enum GFG { Welcome, To, The, World, of, Geeks } ; public class Enum_Set_Demo { public static void main(String[] args) { // Creating an empty EnumSet // Getting all elements from GFG EnumSet<GFG> e_set = EnumSet.allOf(GFG. class ); ; // Displaying the empty EnumSet System.out.println( "Initial set: " + e_set); // Cloning the set EnumSet<GFG> final_set = e_set.clone(); // Displaying the final set System.out.println( "The updated set is:" + final_set); } } |
输出:
Initial set: [Welcome, To, The, World, of, Geeks] The updated set is:[Welcome, To, The, World, of, Geeks]
项目2:
// Java program to demonstrate clone() method import java.util.*; // Creating an enum of CARS type enum CARS { RANGE_ROVER, MUSTANG, CAMARO, AUDI, BMW } ; public class Enum_Set_Demo { public static void main(String[] args) { // Creating an empty EnumSet // Getting all elements from CARS EnumSet<CARS> e_set = EnumSet.allOf(CARS. class ); ; // Displaying the empty EnumSet System.out.println( "Initial set: " + e_set); // Cloning the set EnumSet<CARS> final_set = e_set.clone(); // Displaying the final set System.out.println( "The updated set is:" + final_set); } } |
输出:
Initial set: [RANGE_ROVER, MUSTANG, CAMARO, AUDI, BMW] The updated set is:[RANGE_ROVER, MUSTANG, CAMARO, AUDI, BMW]
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END