Created
August 18, 2017 09:31
-
-
Save cberez/58e9a0e236a36ead013418426ff869e2 to your computer and use it in GitHub Desktop.
How to: enrich / contat scala immutable lists from Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import scala.collection.mutable.ListBuffer; | |
import scala.collection.immutable.List; | |
public class Demo { | |
public static void main(String[] args) { | |
List immutable = new List(); | |
ListBuffer mutable = new ListBuffer(); | |
ListBuffer mutable2 = new ListBuffer(); | |
mutable.$plus$eq("1"); | |
mutable2.$plus$eq("2"); | |
mutable.$plus$plus$eq(mutable2); | |
immutable = mutable.toList(); // [ "1", "2" ] | |
mutable.$plus$plus$eq(immutable); | |
immutable = mutable.toList(); // [ "1", "2", "1", "2" ] | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment