merge mail Addresses - Java Network

Java examples for Network:Network Address

Description

merge mail Addresses

Demo Code


//package com.java2s;
import java.util.ArrayList;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;

public class Main {
    public static void main(String[] argv) throws Exception {
        List in = java.util.Arrays.asList("asdf", "java2s.com");
        System.out.println(mergeAddresses(in));
    }/*  w  ww.  j a v a 2  s .  c o m*/

    public static List<InternetAddress> mergeAddresses(
            List<InternetAddress>... in) throws AddressException {
        Set<String> emails = new HashSet<>();
        List<InternetAddress> ret = new ArrayList<InternetAddress>();
        for (List<InternetAddress> la : in) {
            for (InternetAddress a : la) {
                if (emails.add(a.getAddress())) {
                    ret.add(a);
                }
            }
        }
        return ret;
    }
}

Related Tutorials