当前位置:网站首页>【plang1.4.3】语言新特性:集合
【plang1.4.3】语言新特性:集合
2022-08-02 03:29:00 【ChivenZhang】
为了方便编程,Plang语言加入了体现java.collection设计理念的集合代码库。
以下展示所包含的集合类型:
- Collection:LinkedList、ArrayList、TreeSet、HashSet
- Map:TreeMap、HashMap
集合类提供元素遍历器,使用方法参考如下代码:
import std::IO;
import std::Type;
import std::collection::Collection;
import std::collection::Map;
import std::collection::Iterator;
import std::collection::LinkedList;
import std::collection::ArrayList;
import std::collection::TreeSet;
import std::collection::HashSet;
import std::collection::HashMap;
import std::collection::TreeMap;
class Test {
public static main(){
IO.printf("测试list迭代器\n");
Test.testCollection(new LinkedList());
IO.printf("\n测试vector迭代器\n");
Test.testCollection(new ArrayList());
IO.printf("\n测试hashset迭代器\n");
Test.testCollection(new HashSet(40));
IO.printf("\n测试treeset迭代器\n");
Test.testCollection(new TreeSet());
IO.printf("\n测试hashmap迭代器\n");
Test.testMap(new HashMap());
IO.printf("\n测试treemap迭代器\n");
Test.testMap(new TreeMap());
}
static testCollection(v->Collection){
i->int=0;
while(i<50)v.add(Type.get(i++));
itr->Iterator=v.iterator();
while(itr.hasNext()){
IO.printf("%d ", itr.next()->(Type));
}
}
static testMap(v->Map){
i->int=0;
while(i<50)v.put(Type.get(i), Type.get(100+i++));
itr->Iterator=v.keys();
IO.printf("键:");
while(itr.hasNext()){
IO.printf("%d ", itr.next()->(Type));
}
itr=v.values();
IO.printf("\n值:");
while(itr.hasNext()){
IO.printf("%d ", itr.next()->(Type));
}
}
}Windows10操作系统执行截图:

gitee码云项目链接: plang-1.4.* 工具包
边栏推荐
猜你喜欢
随机推荐
LT9211芯片资料分享
【Arduino connects DHT11 humidity and temperature sensor】
字符串匹配(蛮力法+KMP)
Modify hosts file using batch script
GM8775C MIPI转LVDS调试资料分享
研发过程中的文档管理与工具
openmv学习 2022.5.9
【TCS3200 颜色传感器与 Arduino 实现颜色识别】
《scala 编程(第3版)》学习笔记3
【MQ-3 酒精检测器与 Arduino检测酒精】
功率计,物联网,智能插座电路设计【毕业设计】
How to remotely debug PLC?
【树莓派入门(2)树莓派的远程控制】
PCB Design Ideas
【nRF24L01 connects with Arduino to realize wireless communication】
案例|工业物联网解决方案·智慧钢厂高性能安全数采
【使用树莓派时碰到的一些问题】
MOS管开关原理及应用详解
Spark特征工程-归一化 和 分桶
[Spark]-协同过滤









