Java code to remove duplicates in string
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
String string = "Johnwilliams";
Set<Character> c = new LinkedHashSet<Character>();
for(int i=0;i<string.length();i++)
{
c.add(string.charAt(i));
}
for(char c1:c)
{
System.out.print(c1);
}
}
}
import java.util.*;
public class Solution {
public static void main(String[] args) {
String string = "Johnwilliams";
Set<Character> c = new LinkedHashSet<Character>();
for(int i=0;i<string.length();i++)
{
c.add(string.charAt(i));
}
for(char c1:c)
{
System.out.print(c1);
}
}
}
Comments
Post a Comment