• As3.0中的Dictionary使用测试


    代码如下:

    package
    {
        import flash.display.Sprite;
        import flash.utils.Dictionary;
        
        public class AsTestDemo extends Sprite
        {
            public function AsTestDemo()
            {
                //类似于Java中的Map
                var dict:Dictionary = new Dictionary();
                
                //Dictionary强大之处
                dict[3.01] = "vokie";
                dict["123"] = -100;
                dict[123] = 100;
                dict[8] = 2.11;
                
                trace(dict[3.01]);
                trace(dict.hasOwnProperty(3+0.01)); //Java.Map.ContainsKey
                trace(dict.hasOwnProperty("3.01"));
                trace(dict.hasOwnProperty(123));
                trace(dict.hasOwnProperty(1234));
                trace("--------------------");
                for(var s1:String in dict)  //for(in)语句迭代key
                {
                    trace("key:"+s1);
                }
                trace("--------------------");
                for each(var s2:String in dict) //for each(in)语句迭代value
                {
                    trace("value:"+s2);
                }
            }
        }
    }


    运行结果:

    vokie
    true
    true
    true
    false
    --------------------
    key:8
    key:123
    key:3.01
    --------------------
    value:2.11
    value:100
    value:vokie


    测试结果中的键值覆盖,以及key、value的类型很随意,无需一一对应,使用的时候需要注意

  • 相关阅读:
    shell命令finger
    join命令
    日志记录
    shell命令xargs
    linux read 简介
    P1601 A+B Problem(高精)
    P2670 [NOIP2015 普及组] 扫雷游戏
    P1042 [NOIP2003 普及组] 乒乓球
    P1328 [NOIP2014 提高组] 生活大爆炸版石头剪刀布
    P5744 【深基7.习9】培训
  • 原文地址:https://www.cnblogs.com/vokie/p/3602070.html
Copyright © 2020-2023  润新知