Rajkumar Goel wrote:

> What is the difference between List.flatten and List.concat
> Both do the same operation ,then why two lists.

Hello Raj,
They both return the concatenation but one takes a list as a parameter &
other takes list of lists...

*def concat  [A](xss : List[A]) : List[A]*

Concatenate all the argument lists into a single list.

Parameters
   xss - the lists that are to be concatenated
Returns
   the concatenation of all the lists...

scala> List.concat(List('a'),List('b'))
res0: List[Char] = List(a, b)



*def flatten[A](xss : List[List[A]]) : List[A]*

Concatenate all the elements of a given list of lists.

Parameters
   xss - the list of lists that are to be concatenated
Returns
   the concatenation of all the lists...


scala> val xss = List(List('c'),List('d'),List('e'))
xss: List[List[Char]] = List(List(c), List(d), List(e))

scala> List.flatten(xss)
res1: List[Char] = List(c, d, e)



hope this helps.



-- 
Cheers,
Pratik K Anand


[Non-text portions of this message have been removed]

Reply via email to