【plang1.4.3】语言新特性:集合

    为了方便编程,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.* 工具包

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ChivenZhang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值