java之运算符

package com.simope.myTest;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Test20151026 {

    public static void main(String[] args) {
        
        //乘除法运算最好使用移位运算,效率快
//        左移两位    1000 -> 100000
//        右移三位    1000 -> 1
        System.out.println("8 << 2:" + (8 << 2));            
        
        System.out.println("8 >> 3:" + (8 >> 3));    
        
        System.out.println("17 >>> 3:" + (17 >>> 3));    
        
        System.out.println("***********************************");
        
        int a = 11, b = 17;
//        两个操作数中位都为1,结果才为1,否则结果为0    11:1011、17:10001 -> 1:1
        System.out.println("a & b:" + (a & b));    
        
//        两个位只要有一个为1,那么结果就是1,否则就为0    11:1011、17:10001 -> 11011:27
        System.out.println("a | b:" + (a | b));
        
//        如果位为0,结果是1,如果位为1,结果是0    11:1011 -> 0100
        System.out.println("~a:" + (~a));
        
//        两个操作数的位中,相同则结果为0,不同则结果为1    11:1011、17:10001 -> 11010:26
        System.out.println("a^b:" + (a ^ b));
        
        System.out.println("***********************************");
        
        //此遍历是map遍历效率最高的方法
        Map<String, Object> map = new HashMap<String, Object>();
        
        map.put("name", "张三");
        map.put("age", "21");
        map.put("sex", "man");
        map.put("scholl", "HBUT");
        
        Iterator<Map.Entry<String, Object>> iter = map.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry<String, Object> entry = iter.next();
            System.out.println("key:" + entry.getKey() + " value:" + entry.getValue());
        }
        
        System.out.println("***********************************");
        
        
    }
    
}

 

posted @ 2015-12-07 17:27  Answer.AI.L  阅读(355)  评论(0编辑  收藏  举报