Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala: good way to keep pairs of strings

What is a neat way to hold pairs of strings which are not necessarily key-values (might have duplicate keys), for a small collection? List[List[String]] works obviously but looks dirty.

Cheers
Parsa

like image 356
parsa Avatar asked Oct 17 '10 12:10

parsa


2 Answers

List[(String,String)] is the standard solution:

scala> List(("foo","bar"), ("foo","baz"))
res1: List[(java.lang.String, java.lang.String)] = List((foo,bar), (foo,baz))
like image 88
Fred Foo Avatar answered Oct 04 '22 12:10

Fred Foo


Tuples are the ideal data structure to represent pairs.

So use a list of (String, String) tuples.

like image 39
sepp2k Avatar answered Oct 04 '22 13:10

sepp2k