This is a Java program that demonstrates how to find the non-common elements between two TreeSet objects.
import java.io.*; import java.util.*; public class NonCommon_Element { public static void main(String args[]) { TreeSet <String> num1 = new TreeSet <String>(); num1.add("Blue"); num1.add("Yellow"); num1.add("Red"); num1.add("Green"); num1.add("White"); TreeSet <String> num2 = new TreeSet <String>(); num2.add("Orange"); num2.add("Yellow"); num2.add("Green"); num2.add("Pink"); System.out.println("TreeSet 1 Elements : " + num1); System.out.println("TreeSet 2 Elements : " + num2); num1.addAll(num2); System.out.println("\nTreeSet 1 Elements : " + num1); System.out.println("TreeSet 2 Elements : " + num2); } }
TreeSet 1 Elements : [Blue, Green, Red, White, Yellow] TreeSet 2 Elements : [Green, Orange, Pink, Yellow] TreeSet 1 Elements : [Blue, Green, Orange, Pink, Red, White, Yellow] TreeSet 2 Elements : [Green, Orange, Pink, Yellow]
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions