Set intersection of two strings

Posted by user1785712 on Stack Overflow See other posts from Stack Overflow or by user1785712
Published on 2012-12-15T16:54:45Z Indexed on 2012/12/15 17:03 UTC
Read the original article Hit count: 136

Filed under:
|
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

© Stack Overflow or respective owner

Related posts about java

Related posts about set