Map类
Map同时保存一个索引键(Keys)和一个值(Values),键和值都可以是指定的数据类型。
键不能重复,但值可以重复。所以,多个键可以指向同一个值,但是一个键只能有一个值。
当插入的键已经存在时,Map会使用新的值替换旧的值。Map会根据Key进行自动排序。
这里使用MapEnumerator枚举输出。
static
void MapJob(Args _args)
{
Map m_Map = new Map(Types::Integer,Types::String);
MapEnumerator m_MapEtor;
;
m_Map.insert( 1, " A ");
m_Map.insert( 1, " B ");
m_Map.insert( 4, " C ");
m_Map.insert( 2, " C ");
info(strfmt( " 总元素个数:%1 ",m_Map.elements())); // 3
if(m_Map.exists( 2))
info(strfmt( " 值:%1 ",m_Map.lookup( 2))); // C
info(m_Map.toString());
m_MapEtor = m_Map.getEnumerator();
while(m_MapEtor.moveNext())
{
info(strfmt( " Key:%1,Value:%2 ",m_MapEtor.currentKey(),m_MapEtor.currentValue()));
}
}
{
Map m_Map = new Map(Types::Integer,Types::String);
MapEnumerator m_MapEtor;
;
m_Map.insert( 1, " A ");
m_Map.insert( 1, " B ");
m_Map.insert( 4, " C ");
m_Map.insert( 2, " C ");
info(strfmt( " 总元素个数:%1 ",m_Map.elements())); // 3
if(m_Map.exists( 2))
info(strfmt( " 值:%1 ",m_Map.lookup( 2))); // C
info(m_Map.toString());
m_MapEtor = m_Map.getEnumerator();
while(m_MapEtor.moveNext())
{
info(strfmt( " Key:%1,Value:%2 ",m_MapEtor.currentKey(),m_MapEtor.currentValue()));
}
}