Saturday 3 May 2014

EnumSet : clone() : Returns a copy of this set

public EnumSet<E> clone()
Returns a copy of this set.

import java.util.*;

class EnumSetClone{
 enum Day{
  MON,
  TUE,
  WED,
  THU,
  FRI,
  SAT,
  SUN;
 }
 
 public static void main(String args[]){
  EnumSet<Day> mySet1 = EnumSet.allOf(Day.class);
  
  System.out.println("Elements in mySet1 are");
  System.out.println(mySet1);
  
  EnumSet<Day> mySet2 = mySet1.clone();
  
  System.out.println("Elements in mySet2 are");
  System.out.println(mySet2);
 }
}

Output
Elements in mySet1 are
[MON, TUE, WED, THU, FRI, SAT, SUN]
Elements in mySet2 are
[MON, TUE, WED, THU, FRI, SAT, SUN]

Prevoius                                                 Next                                                 Home

No comments:

Post a Comment