Scala : Map function example using eclipse

For integration of scala with eclipse please refer blog :-

https://haritbigdata.wordpress.com/2016/01/15/add-scala-ide-with-eclipse/
As we Know Map works by applying a function to each element in the list.

 

Following program will help you :-

 

object helloworld1 extends App{

//System.out.print(“hello”);

val lines = Array(“hello”,”hw are you”,”hw you there”);

val count = lines.length;
println(count);

//val filter1=lines.filter(_.contains(“hw”));

val mp1 = lines.map(s => (1,s))

val mp2 = lines.map(a => a + “harit”);

for(x <- mp1)
{
println(x)
print(“\n”);
}

for(y <- mp2)
{
println(y);
}

}

 

 

Output :-

3
(1,hello)

(1,hw are you)

(1,hw you there)

helloharit
hw are youharit
hw you thereharit

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s