当前位置:网站首页>【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.* 工具包
边栏推荐
- 研发过程中的文档管理与工具
- MPU6050 加速度计和陀螺仪传感器与 Arduino 连接
- NE5532运放加法器
- 【Popular Science Post】Detailed explanation of MDIO interface
- Typora use
- MC1496乘法器
- [Popular Science Post] I2C Communication Protocol Detailed Explanation - Partial Software Analysis and Logic Analyzer Example Analysis
- 振芯科技GM8285C:功能TTL转LVDS芯片简介
- 基于树莓派的智能箱包开发环境搭建
- 蛮力法求解凸包问题
猜你喜欢
随机推荐
《scala 编程(第3版)》学习笔记4
Vision Transformer(ViT)论文精读和Pytorch实现代码解析
【Arduino 连接 SD 卡模块实现数据读写】
uniCloud通讯录实战
Spark数据读取和创建
uniCloud使用
如何快速搭建属于自己的物联网平台?
01背包问题(动态规划)
[Arduino uses a rotary encoder module]
How to remotely debug PLC?
MIPI解决方案 ICN6202:MIPI DSI转LVDS转换芯片
IoT solution
【树莓派入门(2)树莓派的远程控制】
[Spark]-LSH局部敏感哈希
Host your own website with Vercel
【Popular Science Post】Detailed explanation of MDIO interface
网站开发方案研究
单火线开关设计详解
Typora使用
Spark MLlib特征处理 之 StringIndexer、IndexToString使用说明以及源码剖析









