We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.io.*;importjava.util.*;importjava.util.regex.Pattern;importjava.util.regex.Matcher;publicclassSolution{publicstaticvoidmain(String[]args){Scannerscanner=newScanner(System.in);intn=scanner.nextInt();scanner.nextLine();// Before and After @: (word.word.word...), with atleast one word, where each word is \w+Patternpattern=Pattern.compile("\\w+(\\.\\w+)*@\\w+(\\.\\w+)*");// Creating hashset to hold unique emailsHashSet<String>hashset=newHashSet<String>();for(inti=0;i<n;i++){Matchermatcher=pattern.matcher(scanner.nextLine());while(matcher.find())hashset.add(matcher.group());}// Converting hashset to arraylist in order to use sort()ArrayListarraylist=newArrayList<String>(hashset);// Sorting arraylist in lexicographical orderCollections.sort(arraylist);// Using ListIterator to iterate through arraylistListIterator<String>iterator=arraylist.listIterator();while(iterator.hasNext()){System.out.print(iterator.next());if(iterator.hasNext())System.out.print(";");}}}
Cookie support is required to access HackerRank
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 15