Intersection of two strings in Java

前端 未结 10 1328
春和景丽
春和景丽 2020-11-30 07:48

Need a Java function to find intersection of two strings. i.e. characters common to the strings.

Example:

String s1 = new String(\"Sychelless\");
St         


        
10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 08:41

    s1.contains(s2) returns true;
    s1.indexOf(s2) returns 0. 
    s1.indexOf("foo") returns -1
    

    For more sophisticated cases use class Pattern.

提交回复
热议问题