Java String with different characters

Description

Java String with different characters


//package com.demo2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String a = "12345";
        String b = "65432";
        System.out.println(allDifferentDigits(a, b));
    }//from  w  w w  . j  a  v a 2s  .com

    public static boolean allDifferentDigits(long a, long b) {
        return areDisjoint(String.valueOf(a), String.valueOf(b));
    }

    public static boolean areDisjoint(String s1, String s2) {
        if (s1 == null || s2 == null)
            return true;
        for (int i = 0; i < s1.length(); i++) {
            if (s2.indexOf(s1.charAt(i)) != -1)
                return false;
        }
        return true;
    }
}



PreviousNext

Related