Initial Checkin
This commit is contained in:
21
SetTest1.java
Normal file
21
SetTest1.java
Normal file
@@ -0,0 +1,21 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user