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

相关文章:

  • 2021-11-16
  • 2021-04-06
  • 2021-10-08
  • 2021-06-06
  • 2021-12-29
  • 2021-10-14
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
  • 2022-12-23
  • 2021-08-17
  • 2021-10-03
  • 2021-06-24
相关资源
相似解决方案