public static String toChecksumAddress(String address) {
        String lowercaseAddress = Numeric.cleanHexPrefix(address).toLowerCase();
        String addressHash = Numeric.cleanHexPrefix(Hash.sha3String(lowercaseAddress));

        StringBuilder result = new StringBuilder(lowercaseAddress.length() + 2);

        result.append("0x");

        for (int i = 0; i < lowercaseAddress.length(); i++) {
            if (Integer.parseInt(String.valueOf(addressHash.charAt(i)), 16) >= 8) {
                result.append(String.valueOf(lowercaseAddress.charAt(i)).toUpperCase());
            } else {
                result.append(lowercaseAddress.charAt(i));
            }
        }

        return result.toString();
    }
@Test
    public void testToChecksumAddress() {
        // Test cases as per https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md#test-cases

        assertEquals(
                Keys.toChecksumAddress("0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359"),
                ("0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359"));

        // All uppercase
        assertEquals(
                Keys.toChecksumAddress("0x52908400098527886E0F7030069857D2E4169EE7"),
                ("0x52908400098527886E0F7030069857D2E4169EE7"));
        assertEquals(
                Keys.toChecksumAddress("0x8617E340B3D01FA5F11F306F4090FD50E238070D"),
                ("0x8617E340B3D01FA5F11F306F4090FD50E238070D"));

        // All lowercase
        assertEquals(
                Keys.toChecksumAddress("0xde709f2102306220921060314715629080e2fb77"),
                ("0xde709f2102306220921060314715629080e2fb77"));
        assertEquals(
                Keys.toChecksumAddress("0x27b1fdb04752bbc536007a920d24acb045561c26"),
                ("0x27b1fdb04752bbc536007a920d24acb045561c26"));

        // Normal
        assertEquals(
                Keys.toChecksumAddress("0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"),
                ("0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"));
        assertEquals(
                Keys.toChecksumAddress("0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359"),
                ("0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359"));
        assertEquals(
                Keys.toChecksumAddress("0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB"),
                ("0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB"));
        assertEquals(
                Keys.toChecksumAddress("0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb"),
                ("0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb"));
    }