@@ -0,0 +1,1659 @@
+package java_problems.data_structures;%0D%0A%0D%0Aimport java.util.*;%0D%0A%0D%0A/*%0D%0A * In computer science, a set is an abstract data type that can store certain%0D%0A * values, without any particular order, and no repeated values(Wikipedia).%0D%0A * %7B1,2,3%7D is an example of a set, but %7B1,2,2%7D is not a set. Today you will%0D%0A * learn how to use sets in java by solving this problem.%0D%0A * %0D%0A * You are given n pairs of strings. Two pairs (a,b) and (c,d) are identical if%0D%0A * a=c and b=d. That also implies (a,b) is not same as (b,a). After taking each%0D%0A * pair as input, you need to print number of unique pairs you currently have.%0D%0A * %0D%0A * Note: Brute force solution will not earn full points.%0D%0A * %0D%0A * Input Format:%0D%0A * %0D%0A * In the first line, there will be an integer T denoting number of pairs. Each%0D%0A * of the next T lines will contain two strings separated by a single space.%0D%0A * %0D%0A * Constraints:%0D%0A * 1%3C=T%3C=100000%0D%0A * Length of each string is at most 5 and will consist lower case letters only.%0D%0A * The testcases were generated randomly.%0D%0A * %0D%0A * Output Format:%0D%0A * %0D%0A * Print T lines. In the ith line, print number of unique pairs you have after%0D%0A * taking ith pair as input.%0D%0A * %0D%0A * Sample Input:%0D%0A * 5%0D%0A * john tom%0D%0A * john mary%0D%0A * john tom%0D%0A * mary anna%0D%0A * mary anna%0D%0A */%0D%0Apublic class JavaHashset %7B%0D%0A%0D%0A    public static void main(String%5B%5D args) %7B%0D%0A        Scanner sc = new Scanner(System.in);%0D%0A        HashSet%3CString%3E hs = new HashSet%3C%3E();%0D%0A        int numPairs = sc.nextInt();%0D%0A        sc.nextLine();%0D%0A        for (int i = 0; i %3C numPairs; i++) %7B%0D%0A            hs.add(sc.nextLine());%0D%0A            System.out.println(hs.size());%0D%0A        %7D%0D%0A        sc.close();%0D%0A    %7D%0D%0A%7D

Add JavaHashset