Skip to content

Instantly share code, notes, and snippets.

@cberez
Created August 18, 2017 09:31
Show Gist options
  • Save cberez/58e9a0e236a36ead013418426ff869e2 to your computer and use it in GitHub Desktop.
Save cberez/58e9a0e236a36ead013418426ff869e2 to your computer and use it in GitHub Desktop.
How to: enrich / contat scala immutable lists from Java
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