groovy之List声明

声明List

def myList = [1,2,3]
assert myList.size() == 3
assert myList.contains(2)
assert myList instanceof ArrayList
def emptyList = []
assert emptyList.size() == 0

def longList = (1..1000).toList()
assert longList.size() == 1000

def lst = new ArrayList()
lst.addAll(myList)
assert lst == myList

def linkList = new LinkedList(myList)
assert linkList.size() == 3
assert linkList[1] == 2

 

你可能感兴趣的:(groovy)