zoukankan      html  css  js  c++  java
  • 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的类型很随意,无需一一对应,使用的时候需要注意

  • 相关阅读:
    Dreamweaver采用utf8制作页面,到.net显示乱码问题解决
    看不完的风景,走不完的路
    整个世界都在返利
    Google 地图小工具:让别人找到你
    开心网
    提取国家地理图片总结
    [脚本收集]:在线词典
    提取国家地理图片总结之二
    [脚本收集]提取国家地理图片
    若我离去,后会无期
  • 原文地址:https://www.cnblogs.com/vokie/p/3602070.html
Copyright © 2011-2022 走看看