Scala Array Programs
- Scala program to implement a one-dimensional array using Array() function
- Scala program to create an integer array using the new keyword
- Scala program to access array elements using foreach loop
- Scala program to get the size of an array
- Scala program to find the largest element from the array
- Scala program to find the second largest element from the array
- Scala program to find the EVEN numbers from the array
- Scala program to calculate the sum of array elements
- Scala program to reverse an integer array
- Scala program to find the prime numbers from the array
- Scala program to search an item into the array using linear search
- Scala program to search an item into the array using binary search
- Scala program to search an item into the array using interpolation search
- Scala program to sort an array in descending order using selection sort
- Scala program to sort an array in descending order using selection sort
- Scala program to sort an array in ascending order using quicksort with recursion
- Scala program to sort an array in ascending order using bubble sort
- Scala program to sort an array in descending order using bubble sort
- Scala program to sort an array in ascending order using insertion sort
- Scala program to sort an array in descending order using insertion sort
- Scala program to Cyclically Permutes the Elements of an Array
- Scala program to delete an item from the array
- Scala program to insert an item into an array
- Scala program to concatenate two integer arrays
- Scala program to merge two integer arrays into a third array
- Scala program to create an array of strings
- Array Rotation in Scala
- Scala program to find the odd occurrences in an array
- Scala program to create strings array
- Scala program to convert Array to string
- Scala program to convert multiline strings to an array
- Scala program to merge two arrays or array buffer
- How to extract unique elements from sequences in Scala?
- Scala program to create a two-dimensional array by using an array of array
- Scala program to read and print MATRIX using a two-dimensional array
- Scala program to calculate the sum of matrix elements
- Scala program to calculate the sum of rows of matrix elements
- Scala program to calculate the sum of columns of matrix elements
- Scala program to print the transpose of MATRIX
- Scala program to print the left diagonal of MATRIX
- Scala program to print the right diagonal of MATRIX
- Scala program to print the sum of left diagonal elements of MATRIX
- Scala program to print the sum of right diagonal elements of MATRIX
- Scala program to add two integer arrays
- Scala program to subtract an array from another array
- Scala program to add two matrices
- Scala program to swap adjacent elements in the array
- Scala program to find the total occurrences of a given item in the array
- Scala program to find the first repeated item in the array
- Scala program to multiply two matrices
- Scala program to demonstrate the 3D array
- Scala program to create the clone of an array
- Scala program to demonstrate the copyToArray() method
- Scala program to print the index of the first occurrence of item using indexOf() method
- Scala program to print the index of the last occurrence of item using lastIndexOf() method
- Scala program to print the common elements of two arrays
- Scala program to print the distinct elements of the array
- Scala program to print the size of the array
- Scala program to get the first N number of elements from the array
- Scala program to get the last N number of elements from the array
Creating a string array in Scala
You can initialize an array using the Array keyword. To know more about creating a Scala array, read: Scala Arrays
There are multiple ways to create a string array in Scala.
Method 1:
If you know all elements of the array in advance, you can initialize the Scala array in the following manner.
Program:
Output
Method 2:
If you don't know the elements of the string in advance but know the number of elements present in the array, then we will create an empty array of definite size first then feed elements to it.
Program:
Output
Creating Mutable Strings Array in Scala
You can create a string array even when you do not know the size and element of the array. For this, we will create a mutable string. This mutable string is created using
ArrayBuffer class whereas others were created using Array class.
To create a mutable string we need to import mutable.ArrayBuffer in your program using,
Program:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer