compare array and arraylist of groovy ; arrayList is alway useful

 

OperationArrayArrayList
Initializationdef arr = [1, 2, 3]def list = [1, 2, 3] as ArrayList
Create Emptydef arr = [] as int[]def list = new ArrayList()
Add ElementNot directly supportedlist.add(element) or list << element
Add Multiple ElementsNot directly supportedlist.addAll([element1, element2])
Access Element by Indexarr[index]list[index]
Modify Element by Indexarr[index] = valuelist[index] = value
Remove Element by IndexNot directly supportedlist.remove(index)
Remove Element by ValueNot directly supportedlist.remove(value)
Check if Emptyarr.isEmpty()list.isEmpty()
Get Sizearr.size()list.size()
Iterate (for-each loop)for (element in arr)for (element in list)
Iterate (for loop)for (i = 0; i < arr.size(); i++)for (i = 0; i < list.size(); i++)
Contains Elementelement in arrelement in list
Sort (In-place)arr.sort()list.sort()
Sort (Create Sorted Copy)def sortedArr = arr.sort(false)def sortedList = list.sort(false)
Join Elements into Stringarr.join(", ")list.join(", ")

Popular posts from this blog

pss book : శ్రీకృష్ణుడు దేవుడా, భగవంతుడా completed , second review needed. 26th April 2024

pss book: గురు ప్రార్థనామంజరి . completed 21st july 2024

pss book: కధల జ్ఞానము read review pending. 25th june 2024