简体   繁体   中英

how to get keys from Map scala irrespective of case

How do i achieve the same result in scala.

Map<String, Integer> lookup = 
    new TreeMap<String, Integer>(String.CASE_INSENSITIVE_ORDER);

lookup.put("One", 1);
lookup.put("tWo", 2);
lookup.put("thrEE", 3);

System.out.println(lookup.get("Two"));
System.out.println(lookup.get("three"));

It's not that it's "unable to do the same" so much as you are unable to figure out how ;)

 scala> scala.collection.immutable.SortedMap("foo" -> "bar")(Ordering.by(_.toLowerCase)).get("Foo")
 res10: Option[String] = Some(bar)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM