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
531 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
1 answer

Hadoop query regarding setJarByClass method of Job class

setJarByClass method basically tells the nodes where ...READ MORE

answered Apr 15, 2018 in Big Data Hadoop by Shubham
• 13,490 points
2,384 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,466 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
598 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,319 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
4,238 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,497 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
702 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,770 points
1,303 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,220 points
2,220 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
686 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