Tuesday, 14 July 2015

Java Important Programs

package java3;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

public class met {
                public static int output1;

                public static void fn(String ip1, String ip2) {
                                String s = ip1.replace(" ", "");
                                String s1 = ip2.replace(" ", "");
                                List<Character> l1 = new ArrayList<Character>();
                                List<Character> l2 = new ArrayList<Character>();
                                for (int i = 0; i < s.length(); i++)
                                                l1.add(s.charAt(i));
                                for (int j = 0; j < s1.length(); j++)
                                                l2.add(s1.charAt(j));
                                l1.retainAll(l2);
                                Set<Character> set = new TreeSet<Character>(l1);
                                l1 = new ArrayList<Character>(set);
                                output1 = l1.size();
                }

                public static void main(String[] args) {
                                fn("a black cow", "battle ship");
                                System.out.println(output1);
                }

}