Guest User

Zalora

a guest
Oct 18th, 2018
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4.  
  5.  
  6. public class Dice {
  7.     public static void main(String[] args) throws IOException{
  8.         //Create List A with Zalora Emails
  9.         String lista[]={"pawansahai@live.com","pawan29sahai@gmail.com"};
  10.         //Create List B with third party emails
  11.         String listb[]={"pawansahai1@live.com","pawan29sahai@gmail.com","pawan29sahai2@gmail.com"};
  12.         //sizes
  13.         int n1=lista.length;
  14.         int n2=listb.length;
  15.         //Output Arraylist
  16.         ArrayList<String> ar=new ArrayList<String>();
  17.         //Hashmap to remove duplicates
  18.         HashMap<String,String> hm=new HashMap<>();
  19.         for(int i=0;i<n1;i++){
  20.             //set both keys and values in hashmap of list A
  21.             hm.put(lista[i],lista[i]);
  22.  
  23.         }
  24.         for(int i=0;i<n2;i++){
  25.             //check if the email already exists
  26.             if(hm.containsKey(listb[i])){
  27.                 hm.put(listb[i],listb[i]);
  28.             }
  29.             else{
  30.                 //unique email id
  31.                 ar.add(listb[i]);
  32.             }
  33.  
  34.  
  35.         }
  36.         //Output the result
  37.         for(int i=0;i<ar.size();i++){
  38.  
  39.             System.out.println(ar.get(i));
  40.         }
  41.  
  42.  
  43.     }
  44. }
Add Comment
Please, Sign In to add comment