package org.JavaIncloud.java ;
import java.util.HashSet ;
import java.util.Iterator ;
import java.util.Set ;
public class CommonOpetationWithSet
{
public static void main
( String ...
JavaInCloud ) {
Set< String> luxuryBike = new HashSet< String> ( ) ;
//List will not give an exception if you'll try adding duplicate element but it'll simply ignore while storing
luxuryBike.add ( "MTT-Turbine" ) ; luxuryBike.add ( "Coventry-Eagle" ) ;
luxuryBike.add ( "Fighter-Combat " ) ; luxuryBike.add ( "Wazuma-V8" ) ;
luxuryBike.add ( "Brough-Superior " ) ; luxuryBike.add ( "Ferrari 900" ) ;
luxuryBike.add ( "Harley-Davidson" ) ; luxuryBike.add ( "Harley-Davidson" ) ;
System .
out .
println ( "luxuryBike>>" + luxuryBike
) ; //luxuryBike>>[Coventry-Eagle, Fighter-Combat , Brough-Superior , Wazuma-V8, Harley-Davidson, Ferrari 900, MTT-Turbine]
if ( luxuryBike.contains ( "Harley-Davidson" ) )
luxuryBike.remove ( "Harley-Davidson" ) ;
System .
out .
println ( "luxuryBike after removing>>" + luxuryBike
) ; //luxuryBike after removing>>[Coventry-Eagle, Fighter-Combat , Brough-Superior , Wazuma-V8, Ferrari 900, MTT-Turbine]
if ( luxuryBike.size ( ) < 8 && ! luxuryBike.contains ( "Harley-Davidson" ) )
luxuryBike.add ( "Harley-Davidson" ) ;
System .
out .
println ( "luxuryBike>>" + luxuryBike
) ; //luxuryBike>>[Coventry-Eagle, Fighter-Combat , Brough-Superior , Wazuma-V8, Harley-Davidson, Ferrari 900, MTT-Turbine]
//How to use Iterator over Set.
Iterator< String> iterator = luxuryBike.iterator ( ) ;
while ( iterator.hasNext ( ) )
{
}
}
}
cGFja2FnZSBvcmcuSmF2YUluY2xvdWQuamF2YTsKCmltcG9ydCBqYXZhLnV0aWwuSGFzaFNldDsKaW1wb3J0IGphdmEudXRpbC5JdGVyYXRvcjsKaW1wb3J0IGphdmEudXRpbC5TZXQ7CgpwdWJsaWMgY2xhc3MgQ29tbW9uT3BldGF0aW9uV2l0aFNldCAKewoJ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