Home »
Code Examples »
Scala Code Examples
Scala - Create, initialize and process ArrayBuffer Code Example
The code for Create, initialize and process ArrayBuffer
import scala.collection.mutable.ArrayBuffer
object Example {
def main(args: Array[String]) = {
var cities = ArrayBuffer("New Delhi","Mumbai","Chennai")
println(cities);
// Add an element
cities += "Gwalior";
// Add two elements
cities += ("Bhopal", "Banglore");
println(cities);
// Remove an element
cities -= "banglore";
// print third element
println(cities(2));
}
}
/*
Output:
ArrayBuffer(New Delhi, Mumbai, Chennai)
ArrayBuffer(New Delhi, Mumbai, Chennai, Gwalior, Bhopal, Banglore)
Chennai
*/
Code by IncludeHelp,
on August 13, 2022 20:55