You are viewing a single comment's thread. Return to all comments →
Java 8
public static void findEmailAddresses(ArrayList<String> items) { Pattern pattern = Pattern.compile("\\w*\\.?[a-zA-Z_0-9]+@([a-zA-Z_0-9]+\\.)+[a-zA-Z_0-9]+"); HashMap<String, String> hashMap = new HashMap<String, String>(); for (String item : items) { Matcher matcher = pattern.matcher(item); while(matcher.find()) { String value = matcher.group(); hashMap.put(value, value); } } ArrayList<String> outputList = new ArrayList<String>(hashMap.keySet()) ; Collections.sort(outputList); String outputStr = ""; for (String item : outputList) { outputStr += item + ";"; } if (!outputStr.isEmpty()) outputStr = outputStr.substring(0, outputStr.length()-1); System.out.print(outputStr); } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); scanner.nextLine(); ArrayList<String> sentenceArrayList = new ArrayList<String>(); while (scanner.hasNextLine()) { sentenceArrayList.add(scanner.nextLine()); } findEmailAddresses(sentenceArrayList); }
Seems like cookies are disabled on this browser, please enable them to open this website
Detect the Email Addresses
You are viewing a single comment's thread. Return to all comments →
Java 8