How the if-else statement is different for Scala and Java

0 votes
Can anyone explain the differences between the if-else statements for Scala and Java?
Jul 29, 2019 in Apache Spark by Nidha
859 views

1 answer to this question.

0 votes

Hey,

There is one main difference. This statement is an expression in Scala, but not in Java. There, we cannot assign it to a variable because it doesn’t return a value.

Here is an example below:

scala> val x=3

x: Int = 3

scala> val kind= if(x%2==0) "even" else "odd"

kind: String = odd

Java:

int x=3;

String kind;

if(x%2==0)

kind=”even”;

else

kind=”odd”;

Hope this helps!

Check out Java online course to learn more about it.

Thanks!

answered Jul 29, 2019 by Gitika
• 65,910 points

Related Questions In Apache Spark

0 votes
1 answer

How is Apache Spark different from the Hadoop approach?

In Hadoop MapReduce the input data is ...READ MORE

answered May 7, 2018 in Apache Spark by BD Master
990 views
0 votes
1 answer

How SparkSQL is different from HQL and SQL?

Hi, SparkSQL is a special component on the ...READ MORE

answered Jul 3, 2019 in Apache Spark by Gitika
• 65,910 points
3,455 views
0 votes
1 answer

How can we optimize and minimize the memory when work with scala use case?

Hi, There is a term in Scala that is ...READ MORE

answered Jul 5, 2019 in Apache Spark by Gitika
• 65,910 points
698 views
0 votes
1 answer

How can you use "for" statement in scala to print list from collection?

Hi, You can use for loop in scala using ...READ MORE

answered Jul 5, 2019 in Apache Spark by Gitika
• 65,910 points
513 views
0 votes
1 answer

Moving files in Hadoop using the Java API?

I would recommend you to use FileSystem.rename(). ...READ MORE

answered Apr 15, 2018 in Big Data Hadoop by Shubham
• 13,490 points
2,483 views
0 votes
1 answer

Hadoop giving java.io.IOException, in mkdir Java code.

I am not sure about the issue. ...READ MORE

answered May 3, 2018 in Big Data Hadoop by Shubham
• 13,490 points
2,252 views
+1 vote
2 answers
+1 vote
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 11,380 points
10,619 views
0 votes
1 answer
–2 votes
1 answer

What is the difference in Java’s “If..Else” and Scala’s “If..Else”?

Hey, Java’s “If. Else”: In Java, “If. Else” is a statement, ...READ MORE

answered Jul 31, 2019 in Apache Spark by Gitika
• 65,910 points
1,622 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