Java Day 28: RegEx, Patterns, and Intro to Databases
Consider a database table, Emails, which has the attributes First Name and Email ID. Given N rows of data simulating the Emails table, print an alphabetically-ordered list of people whose email address ends in @gmail.com.
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
-
- public class Solution {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int N = in.nextInt();
-
- Pattern pattern = Pattern.compile(emailRegEx);
-
- ArrayList<String> list = new ArrayList<>();
-
- for (int i = 0; i < N; i++) {
- String name = in.next();
- String email = in.next();
- Matcher matcher = pattern.matcher(email);
-
- if (matcher.find()) list.add(name);
- }
-
- Collections.sort(list);
-
- list.forEach(System.out::println);
- }
- }