Scala Program to Create Strings Array

Scala Program to Create Strings Array There may be many doubts when it comes to this article. We hope that after reading this article all doubts will be resolved. Let’s go to the article.

Scala Program to Create Strings Array

Scala Program to Create Strings Array

object myObject 
{ 
	def main(args:Array[String]) 
	{ 
	    val colors = Array("Red", "Blue", "Black", "Green")
	    println("This is an array of string :")
	    for(i <- 0 to colors.length-1){
	        println(colors(i))
	    }
	} 
} 
object myObject 
{ 
	def main(args:Array[String]) 
	{ 
	    val colors = new Array[String](3)
	    
	    colors(0) = "Red"
	    colors(1) = "Blue"
	    colors(2) = "Black"
	    
	    println("This is an array of string :")
	    for(i <- 0 to colors.length-1){
	        println("colors("+i+") : "+colors(i))
	    }
	} 
} 
import scala.collection.mutable.ArrayBuffer

object myObject 
{ 
	def main(args:Array[String]) 
	{ 
	    val colors = new ArrayBuffer[String]()
	    
	    colors += "Red"
	    colors += "Blue"
	    colors += "Black"
	    colors += "Green"
	    
	    println("Mutable string array:")
	    for(i <- 0 to colors.length-1){
	        println("colors("+i+") : " + colors(i))
	    }
	} 
} 
This is an array of string :
Red
Blue
Black
Green
This is an array of string :
colors(0) : Red
colors(1) : Blue
colors(2) : Black
Mutable string array:
colors(0) : Red
colors(1) : Blue
colors(2) : Black
colors(3) : Green

Final Words

Scala Program to Create Strings Array We hope all your doubts about this topic will be resolved. See you again in the next article Thank you.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment