How to convert decimal to binary in Java?

To convert decimal to binary in Java, use Integer.toBinaryString.

Here's how you do it:

int decimalOf170 = 170;

String binaryStringOf170 = Integer.toBinaryString(decimalOf170);

// 10101010
System.out.println(binaryStringOf170);