Share

Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





#Java - Code Snippets for '#Bit Flags' - 1 code snippet(s) found

 Sample 1. Usage of Bit Flags ( Apache Commons )

int male = 1 << 0;
int female = 1 << 1;
      
Flags flag = new Flags(1); // Select the Option
System.out.println(flag); //Prints 0000000000000000000000000000000000000000000000000000000000000001
if(flag.isOn(male)){
   System.out.println("Male"); // Prints Male
}

if(flag.isOn(female)){
   System.out.println("female");
}
   
flag = new Flags(2); // Select the Option
System.out.println(flag); //Prints 0000000000000000000000000000000000000000000000000000000000000010
if(flag.isOn(male)){
   System.out.println("Male");
}
   
if(flag.isOn(female)){
   System.out.println("female"); // prints female
}

   Like      Feedback     Bit Flags   Apache Commons



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus