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的类型很随意,无需一一对应,使用的时候需要注意

  • 相关阅读:
    阿里云磁盘扩容
    【Vue】WebPack 忽略指定文件或目录
    MySQL 全文索引 (FullText)
    产品设计
    13-Java面向对象-抽象类与接口
    06-数据存储
    07-网络与通信-02-Android中基于HTTP的通信技术
    10-Android 广播接收器 BroadcastReceiver
    09-Android 中 AIDL 的理解与使用
    09-Android 中 AIDL 的理解与使用
  • 原文地址:https://www.cnblogs.com/vokie/p/3602070.html
Copyright © 2011-2022 走看看