1import java.util.regex.*;
2public class RegexExample1{
3public static void main(String args[]){
4//1st way
5Pattern p = Pattern.compile(".s");//. represents single character
6Matcher m = p.matcher("as");
7boolean b = m.matches();
8
9//2nd way
10boolean b2=Pattern.compile(".s").matcher("as").matches();
11
12//3rd way
13boolean b3 = Pattern.matches(".s", "as");
14
15System.out.println(b+" "+b2+" "+b3);
16}}
1import java.io.*;
2import java.util.*;
3import java.util.Collections;
4import java.util.regex.*;
5
6public class Solution {
7
8 public static void main(String[] args) {
9 Scanner scanner = new Scanner(System.in);
10 int num = scanner.nextInt();
11 String emailRegEx = ".+@gmail\\.com$";
12 Pattern pattern = Pattern.compile(emailRegEx);
13 List<String> list = new ArrayList();
14 for (int i = 0; i < num; i++){
15 String name = scanner.next();
16 String email = scanner.next();
17 Matcher matcher = pattern.matcher(email);
18 if (matcher.find()){
19 list.add(name);
20 }
21 }
22 Collections.sort(list);
23 for (String name : list){
24 System.out.println(name);
25 }
26 }
27}
28
1static void testTriangle(Shape s) {
2 switch (s) {
3 case Triangle t && (t.calculateArea() > 100) ->
4 System.out.println("Large triangle");
5 case Triangle t ->
6 System.out.println("Small triangle");
7 default ->
8 System.out.println("Non-triangle");
9 }
10}