Possible Duplicate:
Can I use scala List directly in Java ?
Can someone help me with creating scala vector within Java and adding say 50 elements to it? Thanks
If you want to do this efficiently, you'll need to use a builder:
import scala.collection.immutable.Vector;
import scala.collection.immutable.VectorBuilder;
public class VectorTest {
public static void main(String[] args){
VectorBuilder<Integer> vb = new VectorBuilder<Integer>();
for(int i = 0; i < 50; i++)
vb.$plus$eq(Integer.valueOf(i));
Vector<Integer> vec = vb.result();
System.out.println("vec = " + vec);
}
}
import scala.collection.immutable.Vector;
Vector v = Vector.empty();
for(int i = 1; i <51; i++)
{
v = v.appendBack(i);
}
精彩评论