Set intersection of two strings
- by user1785712
import java.util.*;
class set
{
public static void main(String args[])
{
TreeSet<Character> t1 = new TreeSet<Character>();
TreeSet<Character> t2 = new TreeSet<Character>();
String s1 = "Ambitab bachan";
String s2 = "Ranjikanth";
for(char c1:s1.toCharArray())
t1.add(c1);
for(char c2:s2.toCharArray())
t2.add(c2);
t2.retainAll(t1);
System.out.println(t2);
}
}
this program find the common character in two different string. in this program Treeset is used to store the value and retainAll() method is used to find the common characters. can anybody help me reduce the line of coding.thanks in advance