Convert boolean to int in Java

hpique picture hpique · Sep 25, 2010 · Viewed 439.4k times · Source

What is the most accepted way to convert a boolean to an int in Java?

Answer

Jonatha ANTOINE picture Jonatha ANTOINE · Sep 25, 2010
int myInt = myBoolean ? 1 : 0;

^^

PS : true = 1 and false = 0