Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.HashMap;
- public class Dice {
- public static void main(String[] args) throws IOException{
- //Create List A with Zalora Emails
- String lista[]={"pawansahai@live.com","pawan29sahai@gmail.com"};
- //Create List B with third party emails
- String listb[]={"pawansahai1@live.com","pawan29sahai@gmail.com","pawan29sahai2@gmail.com"};
- //sizes
- int n1=lista.length;
- int n2=listb.length;
- //Output Arraylist
- ArrayList<String> ar=new ArrayList<String>();
- //Hashmap to remove duplicates
- HashMap<String,String> hm=new HashMap<>();
- for(int i=0;i<n1;i++){
- //set both keys and values in hashmap of list A
- hm.put(lista[i],lista[i]);
- }
- for(int i=0;i<n2;i++){
- //check if the email already exists
- if(hm.containsKey(listb[i])){
- hm.put(listb[i],listb[i]);
- }
- else{
- //unique email id
- ar.add(listb[i]);
- }
- }
- //Output the result
- for(int i=0;i<ar.size();i++){
- System.out.println(ar.get(i));
- }
- }
- }
Add Comment
Please, Sign In to add comment