zoukankan      html  css  js  c++  java
  • Java boolean operator &=, |= and ^=

    a &= b also means a = a & b
     
    true    &    true    ==>    true
    true    &    false    ==>    false
    false   &    true    ==>    false
    false   &    false    ==>    false
     
    true    |    true    ==>    true
    true    |    false    ==>    true
    false   |    true    ==>    true
    false   |    false    ==>    false
     
    ^=  相同为假,不同为真
    true    ^    true    ==>    false
    true    ^    false    ==>    true
    false   ^    true    ==>    true
    false   ^    false    ==>    false
     
    public class UniqueChar {
        public static boolean isUniqueChars(String str) {
            int checker = 0; //bit storage
            for (int i = 0; i < str.length(); ++i) {
                int val = str.charAt(i) - 'a';
                // if bit at index val is 1, then it already exists
                if ((checker & (1 << val)) > 0) {
                    return false;
                }
    
                //Set bit of index val to 1
                checker |= (1 << val);
            }
            return true;
        }
    }
  • 相关阅读:
    Makefile.am文件配置
    PHP之mb_check_encoding使用
    PHP之mb_internal_encoding使用
    MarkDown编辑使用指南
    test
    [MySQL]修改mysql的root密码
    开启IT之旅_真理不死,信念永恒
    Python pickle 模块
    python注意点
    GAT2.0使用文档(组合接口测试)
  • 原文地址:https://www.cnblogs.com/codingforum/p/8333799.html
Copyright © 2011-2022 走看看