[Training Video - 5] [Groovy Script Test Step - Collections, Exceptions] HashSet and Hashtable

本文通过具体实例展示了Java中HashSet和Hashtable的基本用法。包括如何创建集合、添加元素、获取元素等操作,并展示了集合的大小及元素遍历过程。

Hashset:

HashSet set = new HashSet()
set.add("India")
set.add("USA")
set.add("China")
log.info "Set size is : " + set.size()

set.add("China")
log.info "Set size is : " + set.size()

Iterator iter = set.iterator();
log.info "If has next : " +iter.hasNext()
log.info iter.next()
while(iter.hasNext()){
	log.info iter.next()
}

 Result :

Tue Jun 16 15:02:49 CST 2015:INFO:Set size is : 3
Tue Jun 16 15:02:49 CST 2015:INFO:Set size is : 3
Tue Jun 16 15:02:49 CST 2015:INFO:If has next : true
Tue Jun 16 15:02:49 CST 2015:INFO:USA
Tue Jun 16 15:02:49 CST 2015:INFO:China
Tue Jun 16 15:02:49 CST 2015:INFO:India

Hashtable :

Hashtable table = new Hashtable()
table.put("name","Henry")
table.put("country","Russia")
table.put("telephone","13658988546")
table.put("email","henry.wasley@gmail.com")

log.info "Size of table is " + table.size()
log.info "Name is " + table.get("name")
log.info "Country is " + table.get("country") 

 Result :

Tue Jun 16 15:06:55 CST 2015:INFO:Size of table is 4
Tue Jun 16 15:06:55 CST 2015:INFO:Name is Henry
Tue Jun 16 15:06:55 CST 2015:INFO:Country is Russia

转载于:https://www.cnblogs.com/MasterMonkInTemple/p/4580857.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值