Query regarding ArrayBuffer

0 votes

Hi,

Why we cant use new keyword for creating ArrayBuffer object?

import scala.collection.mutable.ArrayBuffer

val MyArray = new ArrayBuffer(1,2,3,4)    ==>>  Showing me error

val MyArray = ArrayBuffer(1,2,3,4)    ==>>  Working Fine
Jul 26 in Big Data Hadoop by Kunal
16 views

1 answer to this question.

0 votes

It's because that is the syntax. This is the syntax for creating a Scala ArrayBuffer:

import scala.collection.mutable.ArrayBuffer

var fruits = ArrayBuffer[String]()

var ints = ArrayBuffer[Int]()

The key thing to know is that the keyword new is not required before the ArrayBuffer. (This is because ArrayBuffer is either defined as a case class, or because it has an apply method defined. I haven’t looked at its source code to know which approach is taken.)

While I’m in the neighborhood, here are some other ways you can work with ArrayBuffer:

val x = ArrayBuffer('a', 'b', 'c', 'd', 'e')

var characters = ArrayBuffer[String]()

characters += "Ben"

characters += "Jerry"

characters += "Dale"
answered Jul 26 by Rishi

Related Questions In Big Data Hadoop

0 votes
2 answers

Hadoop query regarding setJarByClass method of Job class

http://www.bigdataspeak.com/2014/06/what-is-need-to-use-jobsetjarbycla ...READ MORE

answered Feb 6 in Big Data Hadoop by siri
424 views
0 votes
1 answer

Query regarding Temporary table's metadata in HIVE

Registered tables are not cached in memory. ...READ MORE

answered May 22 in Big Data Hadoop by Tina
17 views
0 votes
1 answer

Query regarding Parquet File type conversion

Suppose I have the below parquet file ...READ MORE

answered Jun 20 in Big Data Hadoop by Stuart
10 views
0 votes
1 answer
0 votes
1 answer

Copy all files from local (Windows) to HDFS with Scala code

Please try the following Scala code: import org.apache.hadoop.conf.Configuration import ...READ MORE

answered May 22 in Apache Spark by Karan
116 views
0 votes
1 answer

Scala pass input data as arguments

Please refer to the below code as ...READ MORE

answered Jun 19 in Apache Spark by Lisa
29 views
0 votes
1 answer

Doubt in display(id, name, salary) before display function

The statement display(id, name, salary) is written before the display function ...READ MORE

answered Jun 19 in Apache Spark by Ritu
23 views
0 votes
1 answer

How to calculate the result of formula with Scala?

Hi, You can use a simple mathematical calculation ...READ MORE

answered Jul 1 in Apache Spark by Gitika
• 25,300 points
37 views
0 votes
1 answer

Query regarding String and Varchar in Hive

Varchar datatype is also saved internally as ...READ MORE

answered Feb 19 in Big Data Hadoop by Omkar
• 67,290 points
114 views
0 votes
1 answer

Query regarding sqoop job

There no way to take any precautions ...READ MORE

answered May 23 in Big Data Hadoop by Imran
18 views