How do I find the characters common to two strings in Java using single replaceAll?

后端 未结 4 731
时光说笑
时光说笑 2021-01-12 16:25

So suppose I have:

String s = \"1479K\";
String t = \"459LP\";

and I want to return

String commonChars = \"49\";

4条回答
  •  甜味超标
    2021-01-12 17:12

    public class common {
    
       public static void main(String args[]) {
          String s = "FIRST";
          String s1 = "SECOND";
          String common = s.replaceAll("[^" + s1 + "]", "");
          System.out.println(common);
       }
    }
    

提交回复
热议问题