Here you can find the source of getEmailListStr(String tempStr)
private static String getEmailListStr(String tempStr)
//package com.java2s; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { private static String getEmailListStr(String tempStr) { List<String> list = new ArrayList<String>(); String regex = "[^a-zA-Z-]To: (.+)"; Pattern ptn = Pattern.compile(regex); Matcher mc = null;//from w w w . j a v a 2 s . c o m mc = ptn.matcher(tempStr); String temp = null; System.out.println("\n\n------------------------------------"); while (mc.find()) { temp = mc.group(1); if (!list.contains(temp)) { System.out.println(temp); list.add(temp); } } if (list == null || list.size() == 0) { return null; } StringBuffer sbf = new StringBuffer(); sbf.append(list.get(0)); for (int i = 1; i < list.size(); i++) { sbf.append("','"); sbf.append(list.get(i)); } sbf.insert(0, "'"); sbf.append("'"); return sbf.toString(); } }