21 lines
604 B
Java
21 lines
604 B
Java
|
|
import java.util.*;
|
||
|
|
|
||
|
|
class SetTest1{
|
||
|
|
public static void main(String []args) {
|
||
|
|
String string1= "ABFED";
|
||
|
|
String string2= "AFBHI";
|
||
|
|
|
||
|
|
Set<Character> set1 = string2CharSet(string1);
|
||
|
|
set1.retainAll(string2CharSet(string2));
|
||
|
|
|
||
|
|
System.out.println(set1.toString());
|
||
|
|
}
|
||
|
|
|
||
|
|
private static Set<Character> string2CharSet(String s1) {
|
||
|
|
Set<Character> set1=new HashSet<Character>();
|
||
|
|
Character[] cha1 = s1.chars().mapToObj(c -> (char) c).toArray(Character[]::new);
|
||
|
|
set1.addAll(Arrays.asList(cha1));
|
||
|
|
return set1;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|