当前位置:网站首页>【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.* 工具包
边栏推荐
猜你喜欢
随机推荐
Go 程序太大了,能要个延迟初始化不?
ArrayList LinkList效率对比
MPU6050 加速度计和陀螺仪传感器与 Arduino 连接
BSN:Boundary-Sensitive Network for Temporal Action Proposal Generation论文阅读笔记
uniCloud address book combat
R语言 —— 多元线性回归
为什么D类音频功放可以免输出滤波器
哈工大2021机器学习期末考试题
无源域适应(SFDA)方向的领域探究和论文复现(第一部分)
【Arduino使用旋转编码器模块】
使用Vercel托管自己的网站
GM8775C规格书,MIPI转LVDS,MIPI转双路LVDS分享
【科普贴】SPI接口详解
Typora use
【plang 1.4.6】Plang高级编程语言(发布)
Typora使用
Scala 中的集合(二):集合性能比较
功率计,物联网,智能插座电路设计【毕业设计】
Comparative analysis of mobile cloud IoT pre-research and Alibaba Cloud development
目标检测(一):R-CNN系列