Day 28: RegEx, Patterns, and Intro to Databases

  • + 0 comments

    import java.util.*;

    public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); // Number of rows scanner.nextLine(); // Consume newline

        List<String> names = new ArrayList<>();
    
        for (int i = 0; i < N; i++) {
            String[] data = scanner.nextLine().split(" ");
            String firstName = data[0];
            String emailID = data[1];
    
            // Check if the email ends with "@gmail.com"
            if (emailID.endsWith("@gmail.com")) {
                names.add(firstName);
            }
        }
    
        // Sort names alphabetically
        Collections.sort(names);
    
        // Print sorted names
        for (String name : names) {
            System.out.println(name);
        }
    
        scanner.close();
    }
    

    }