Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 08c0453

Browse files
committed
Add groupBy and sortBy examples
1 parent 95da43b commit 08c0453

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

‎app/src/main/java/com/annimon/java8streamexample/MainActivity.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ private void action(String action) {
132132
.limit(5))
133133
.map(w -> new Word(String.valueOf(w.getWord().charAt(0)), w.getWord()));
134134
break;
135+
case "group by":
136+
stream = stream.groupBy(w -> w.getWord().charAt(0))
137+
.flatMap(entry -> Stream.of(entry.getValue())
138+
.map(w -> new Word(String.valueOf(entry.getKey()), w.getWord())))
139+
.sortBy(Word::getWord);
140+
break;
141+
case "sort by":
142+
stream = stream.sortBy(Word::getTranslate);
143+
break;
135144
case "random":
136145
final Random rnd = new Random();
137146
stream = Stream.ofRange(0, 10000)

‎app/src/main/res/values/strings.xml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
<item>Skip first N rows</item>
2020
<item>Limit N rows</item>
2121
<item>Group by first character</item>
22+
<item>Group by first character 2</item>
23+
<item>Sort by translate</item>
2224
<item>10000 Random ints</item>
2325
</string-array>
2426

@@ -33,6 +35,8 @@
3335
<item>skip %N</item>
3436
<item>limit %N</item>
3537
<item>group</item>
38+
<item>group by</item>
39+
<item>sort by</item>
3640
<item>random</item>
3741
</string-array>
3842

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /