diff --git a/week3/day1/Classroom/RemoveDuplicates.java b/week3/day1/Classroom/RemoveDuplicates.java index 73c6f9c..142aad0 100644 --- a/week3/day1/Classroom/RemoveDuplicates.java +++ b/week3/day1/Classroom/RemoveDuplicates.java @@ -5,25 +5,65 @@ public class RemoveDuplicates { public static void main(String[] args) { // Declare a String as PayPal India - +String a = "PayPal India"; + // Convert it into a character array +char[] ch= a.toCharArray(); + +for(char c: ch) { + System.out.println(c); +} // Declare a Set as charSet for Character +Set set = new TreeSet (); // Declare a Set as dupCharSet for duplicate Character +Set set1 = new TreeSet (); // Iterate character array and add it into charSet +int length = ch.length; + + for (char eachValue: ch) { + -// if the character is already in the charSet then, add it to the dupCharSet +// if the character is already in the charSet then, add it to the dupCharSet + if(set.contains(eachValue)) { + + set1.add(eachValue); + }else { + set.add(eachValue); + } + } + System.out.println(set); + System.out.println(set1); + + // Check the dupCharSet elements and remove those in the charSet - +for(char eachText: set1) { + if(set.contains(eachText)) { + set.remove(eachText); + }else { + + } +} + + // Iterate using charSet + for(char check: set) { + + // Check the iterator variable isn't equals to an empty space - + if(check!=' ') { + // print it - + + System.out.println("No empty space"); + }else { + System.out.println("Empty space"); + } + } + } - }