From c7ee87cd8dc3f4d86480662ba4af473ccc5d2a77 Mon Sep 17 00:00:00 2001 From: Keerthigavijayakrishnan <110728322+Keerthigavijayakrishnan@users.noreply.github.com> Date: Fri, 26 Aug 2022 23:59:23 +0530 Subject: [PATCH] Update RemoveDuplicates.java Week3.Day2-RemoveDuplicates --- week3/day1/Classroom/RemoveDuplicates.java | 52 +++++++++++++++++++--- 1 file changed, 46 insertions(+), 6 deletions(-) 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"); + } + } + } - }