Skip to content

Commit 423b9d3

Browse files
committed
using collection streams from javascript with nashorn
1 parent 56c19d7 commit 423b9d3

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

res/nashorn3.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,41 @@ list.add('b');
4848
list.add('c');
4949

5050
for each (var el in list) print(el);
51+
52+
53+
print('------------------');
54+
print('HashMap:');
55+
56+
var HashMap = Java.type('java.util.HashMap');
57+
58+
var map = new HashMap();
59+
map.put('foo', 'foo1');
60+
map.put('bar', 'bar1');
61+
62+
for each(var e in map.keySet()) print(e);
63+
64+
for each(var e in map.values()) print(e);
65+
66+
67+
print('------------------');
68+
print('Streams:');
69+
70+
var list2 = new ArrayList();
71+
list2.add("ddd2");
72+
list2.add("aaa2");
73+
list2.add("bbb1");
74+
list2.add("aaa1");
75+
list2.add("bbb3");
76+
list2.add("ccc");
77+
list2.add("bbb2");
78+
list2.add("ddd1");
79+
80+
list2
81+
.stream()
82+
.filter(function(el) {
83+
return el.startsWith("aaa");
84+
})
85+
.sorted()
86+
.forEach(function(el) {
87+
print(el);
88+
});

0 commit comments

Comments
 (0)