Guest User

Untitled

a guest
Jul 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import java.lang.reflect.Array;
  2. import java.util.Arrays;
  3. import java.util.HashSet;
  4.  
  5. public class Solution1 {
  6. public static void main(String[] args){
  7. String[] Set1 = {"A","D","E"};
  8. String[] Set2= {"A","A","D","E"};
  9. boolean isSubset;
  10.  
  11.  
  12. isSubset = checkSubset(Set1,Set2);
  13. System.out.println(Set2 );
  14. System.out.print("Is Set 2 " + Arrays.toString(Set2) + " subset of Set1 " + Arrays.toString(Set1) + "? :" + isSubset);
  15.  
  16. }
  17.  
  18. public static boolean checkSubset(String[] set1, String[] set2) {
  19.  
  20.  
  21. HashSet Set1 = convertArrayIntoHashSet(set1);
  22.  
  23. HashSet Set2= convertArrayIntoHashSet(set2);
  24.  
  25. boolean isContain;
  26. if(Set1.size() > Set2.size()){
  27. return false;
  28. }
  29. for(Object s: Set1){
  30. isContain = Set1.contains(s);
  31. if (isContain == true){
  32. continue;
  33. }else {
  34. return false;
  35. }
  36.  
  37. }
  38. return true;
  39.  
  40. }
  41.  
  42. public static HashSet convertArrayIntoHashSet(String[] set1) {
  43.  
  44. HashSet Set = new HashSet<>();
  45. for (Object element1 : set1) {
  46. Set.add(element1);
  47. }
  48. return Set;
  49. }
  50. }
Add Comment
Please, Sign In to add comment