java set operations

import java.util.*;
public class SetDemo {

  public static void main(String args[]) { 
      int count[] = {34, 22,10,60,30,22};
      Set<Integer> set = new HashSet<Integer>();
      try {
         for(int i = 0; i < 5; i++) {
            set.add(count[i]);
         }
         System.out.println(set);

         TreeSet sortedSet = new TreeSet<Integer>(set);
         System.out.println("The sorted list is:");
         System.out.println(sortedSet);

         System.out.println("The First element of the set is: "+ (Integer)sortedSet.first());
         System.out.println("The last element of the set is: "+ (Integer)sortedSet.last());
      }
      catch(Exception e) {}
   }
} 

0
10
Awgiedawgie 440220 points

                                    s1.containsAll(s2) &mdash; returns true if s2 is a subset of s1. (s2 is a subset of s1 if set s1 contains all of the elements in s2.)
s1.addAll(s2) &mdash; transforms s1 into the union of s1 and s2. (The union of two sets is the set containing all of the elements contained in either set.)
s1.retainAll(s2) &mdash; transforms s1 into the intersection of s1 and s2. (The intersection of two sets is the set containing only the elements common to both sets.)
s1.removeAll(s2) &mdash; transforms s1 into the (asymmetric) set difference of s1 and s2. (For example, the set difference of s1 minus s2 is the set containing all of the elements found in s1 but not in s2.)

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
set in java programs setsin java how to use set in javas make set in java how to use sets in java defining set function java set function java set is java what is a set in java 8 set function example java java define set with values declare set in java java set explained How does set work in java value set java code of set in java .set() java java is in set A set in java ? how is a set in java set(a,0) meaning in java java work with set declaring a set in java what is the use of set in java how to how to set in java set method java example set set java java.util.set in java java creating a set set operations jjava a java set implementing set in java sets methods in java Set&lt;&gt; in java purpose of set in java how to do set in java set in java what is setS in java how to set value for Set java How to code a set in java set - set java set java implementation Set implementation java java set of implement set in java java whats a set java using set how too use set in java creating set in java declare set java java set() java set java set \ set or java use set in java where to use set in java java set operations implement a set in java Set javas java util set example set in java methods java set implementation create new set java java set of set java set.of example how to set java set javaa how to use set method in java set methods java new set javva why we are using set in java declare a set in java whatis set in java java set(i) where can we use set in JAVA\ java create set what is a set java how does a set work in java .set java set in jaba what does .set do in java set operations in java what is set java set method in java implementing a set in to java .set() in java Set java method java is set set function in java java set methods functions of set in java how to create set i java set s = new set() in java set method java java set method \set java set operations java how i can write a set in java creating a set java implementing a set in java create a set in java create set in java code for set operations in java java set syntax set implementation in java create a set java java .set what does this set do in java making a set in java set for java java set functions how to declare set program of set in java how to get an element of a set in java set.add java how to read into set in java set in jva set of strings java is set a collection create a new set java set collection in java collection set in java java define set string of set in java java set of strings define a set in java how to make set in java with custom equivalent how to make set in java set get java java set contains set interface in java how to access elements of a set in java string util to set definition of a Set&lt;T&gt; s in java set example java get value from set in java java set util how to set in set of interger java class Set java set contains java declare set javs define set java display set values in java how to set elements from set in java .set in java mplement a set data structure with the following methods: Set in javaa print set in java how to write a set in alted HOW TO READ FROM SET unordered set in java java methods for sets set string java set add example of set java how to use set set java methods set of strings java set(string,&lt; object &gt;) set add java how to get element from set in java java what is a set used for sets java what are set in java create set in java sample java what is a set java set return only element how to make set in java set opearation in java set() in javq java program to implement set java set programs setcaret in java set methods in java add set to other set java how to set a value to set in java setlookandfeel java example how to dispay 2nd element in set i java return set elements in java Set&lt;String&gt; java (); set data structure java how to make a Set&lt;&gt; in java create a set class in java Example of Set in JAVA set of string java java set collection xample what set in java does set java string value java sets types of sets in java java use of all set java use of set create set type in java how to implement a set in java set sreing java how to construct a set in java how acess elements in set in java get element from set java how to get value from set get values in a set java what is Set in java get all elelemtns in set java Set in Java create how to access element in a a set in jva how to use sets java java make set example codes of set&lt;&gt; in java example codes of set in java java having a set how to get elements from set set java sintax set of objects in java using $set example java set uses use a set that sets collection use a set collection how to make a new set in java make new set in java how to get a set element in java set object into set object to set java Sets in java make my class a Set in java hot to use set in java how to set [] how to create a set&lt;string&gt; in java how to create a set of strings in java java set code how to declare a set in java return everything as a set java set useful in java how to access an element in a set java set java collection example java how to make set create a set of items java java return and set element sets code java how to make Set class in java how to get set elements in java set new set jaa example of a set java how to define a set in java java set set set access element java how to make a set java java how to create set how to get set element in java get in set java how to get set of sets into new set declaration java java how to use set collection java how to used set collection set of objects java create set java set injava how to use java Set&lt;String&gt; java set of objects set of string in java get elements in set java set declaration in java different type of set methods java java set string how to get values from set in java how to get element from a set in java defining a set in java how to make a set in java Java String set type of set in java how to create a set in java how to store set in java access elements in set java how to create set in java string set java storing data in a set java get set element in java new set java get values in set java retrieve values from set in java java new set set structure in java set code in java import set java how to access set in java set string example set string java set string java example set java example write java code to illustrate the concept of set Write a Java code to illustrate the concept of Set is data type set in java how to call set object in java set funtions in java How to use Set in Java Set java Set in java collections Baledung set in java java set predefined methods set functions in java Set&lt;String&gt; java set like type in java how to declare set in java what is a set in java types of sets java set&lt;&gt; java set methods java gfg java code to convert array to set examples java set using a set java using sets java using set java java set example
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source