Scala: Programing in Scala, A Comprehensive Step-by-Step Guide by Chiranjit Hazarika

Scala: Programing in Scala, A Comprehensive Step-by-Step Guide by Chiranjit Hazarika

Author:Chiranjit Hazarika [Hazarika, Chiranjit]
Language: eng
Format: azw3
Published: 2017-10-27T04:00:00+00:00


// Add a 1 to end of the array buffer: nums += 1

printArrayBuffer(nums)

// Add multiple items at once to the end: nums ++= Array(2, 5) printArrayBuffer(nums)

// Add a 3 and a 4 after position 2:

nums.insert(2, 3, 4)

printArrayBuffer(nums)

// To remove an item by its index: nums.remove(3) printArrayBuffer(nums)

// Remove 2 items beginning at index 1: nums.remove(1, 2) printArrayBuffer(nums)

}

}

60

Note that iterating through anArrayBufferis similar to anArray. We can use a simple for loop as per Code Listing 38. We can also use the property calledArrayBuffer.length and loop through the items.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.