Ashwini Khare Ashwini Khare - 1 year ago 345
Scala Question

scala tuple to String

Suppose I have a list of tuples

('a', 1), ('b', 2)...

How would one get about converting it to a String in the format

a 1
b 2

I tried using'\t'))
However I'm getting an error since essentially I'm applying the operation to a tuple instead of a list. Using
didn't help either

Answer Source

For Tuple2 you can use:

val list = List(("1", 4), ("dfg", 67)) { case (str, int) => s"$str $int"}

For any tuples try this code:

val list = List[Product](("dfsgd", 234), ("345345", 345, 456456)) { tuple => 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download