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, 2019 in Big Data Hadoop by Kunal
311 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, 2019 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 7, 2019 in Big Data Hadoop by siri
2,026 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, 2019 in Big Data Hadoop by Tina
1,082 views
0 votes
1 answer

Query regarding Parquet File type conversion

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

answered Jun 20, 2019 in Big Data Hadoop by Stuart
371 views
0 votes
1 answer

Query regarding temporary File type conversion of parquet to text

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

answered Jul 9, 2019 in Big Data Hadoop by Janan
1,103 views
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, 2019 in Apache Spark by Karan
3,697 views
0 votes
1 answer

Scala pass input data as arguments

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

answered Jun 19, 2019 in Apache Spark by Lisa
2,097 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, 2019 in Apache Spark by Ritu
395 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, 2019 in Apache Spark by Gitika
• 65,910 points
1,001 views
0 votes
1 answer

Query regarding String and Varchar in Hive

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

answered Feb 20, 2019 in Big Data Hadoop by Omkar
• 69,210 points
1,779 views
0 votes
1 answer

Query regarding sqoop job

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

answered May 23, 2019 in Big Data Hadoop by Imran
413 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP