java.util.List l = new java.util.LinkedList(); l.add("a"); l.add("b"); l.add("c"); java.util.List s = l.subList(1, 2); s.add("*"); System.out.println(l); // prints [a, b, *, c] s.remove(0); System.out.println(l); // prints [a, *, c] java.util.List r = l.subList(2,3); r.addAll(s); System.out.println(l); // prints [a, *, c, *]
2010-05-25
Java sub lists
This feaute is there for a while but I did not noticed it. It turns out that java.util.List#subList allows not only read but also manipulate original list just like list slice manipulation in Python but with clumsy syntax:
Subscribe to:
Post Comments (Atom)
On security
My VPS recently got banned for spam which surprised me since none of my soft there sending email. So my first thoughts were that this is a...
-
It is harder to write reusable code because it is used in more than one context. In particular it is the case with unit-testable code, beca...
-
My VPS recently got banned for spam which surprised me since none of my soft there sending email. So my first thoughts were that this is a...
No comments:
Post a Comment