• Stars
    star
    114
  • Rank 308,031 (Top 7 %)
  • Language
    Java
  • Created almost 10 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Demo app of using Java 8 features with Retrolambda and Lightweight-Stream-API

Android Java 8 Stream API Example

Demo app of using Java 8 features with Retrolambda and Lightweight-Stream-API.

Features:

  • () -> lambda expression

    findViewById(R.id.go).setOnClickListener(v -> {
       final int index = mActionSpinner.getSelectedItemPosition();
       if (index != Spinner.INVALID_POSITION) {
           action(actions[index]);
       }
    });
  • Method::references

    int cmp = Objects.compare(word, other.word, String::compareToIgnoreCase);
  • Stream.API()

    return Stream.of(lines)
         .map(str -> str.split("\t"))
         .filter(arr -> arr.length == 2)
         .map(arr -> new Word(arr[0], arr[1]))
         .collect(Collectors.toList());
  • switch for "string"

    switch (action) {
        case "filter 1":
            // Filter one word
            stream = stream.filter(p -> p.getWord().split(" ").length == 1);
            break;
        case "filter 2+":
            // Filter two and more words
            stream = stream.filter(p -> p.getWord().split(" ").length >= 2);
            break;
        // ...
    }
  • try(with-resources) {}

    final List<String> lines = new ArrayList<>();
    try (final InputStream is = context.getAssets().open("words.txt");
         final InputStreamReader isr = new InputStreamReader(is, "UTF-8");
         final BufferedReader reader = new BufferedReader(isr)) {
        String line;
        while ( (line = reader.readLine()) != null ) {
            lines.add(line);
        }
    }
  • Objects (from Java 7)

    @Override
    public boolean equals(Object o) {
        // ...
        final Word other = (Word) o;
        return Objects.equals(translate, other.translate) &&
               Objects.equals(word, other.word);
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(word, translate);
    }
  • try { Exceptional } catch (functional try/catch)

    return Exceptional.of(() -> {
        final InputStream is = context.getAssets().open("words.txt");
        // ... operations which throws Exception ...
        return lines;
    }).ifException(e -> Log.e("Java 8 Example", "Utils.readWords", e))
      .getOrElse(new ArrayList<>());

Links

Demo app: Java8StreamExample.apk

Blog (Russian): Java 8 в Android со Stream API и лямбдами

Retrolambda: https://github.com/orfjackal/retrolambda

Lightweight-Stream-API: https://github.com/aNNiMON/Lightweight-Stream-API

Screenshots

screen_1 screen_2

More Repositories

1

Lightweight-Stream-API

Stream API from Java 8 rewritten on iterators for Java 7 and below
Java
1,602
star
2

Own-Programming-Language-Tutorial

Source code for course "How to create your own programming language"
Java
125
star
3

dex-editor

Edit the dalvik-bytecode on Android.
Java
106
star
4

PaperStyleWidgets

Android material-design widgets
Java
38
star
5

MinizipAndroid

Android archiver using minizip library.
C
14
star
6

tgbots-module

Enhanced Java telegram bots runner built on top of the Telegram Bots library
Java
14
star
7

HotaruFX

Programming language for creating animations
Java
12
star
8

ffmpegbot

Telegram ffmpeg bot for re-encoding media
Java
7
star
9

SimpleVM

Simple virtual machine
Java
7
star
10

Flood-It-Bot

Universal bot for flood-it games
Java
6
star
11

JECP

Java Engine Cross-Platform
Java
5
star
12

Piwigo-Color-Palette

Color palette plugin for Piwigo
PHP
5
star
13

SyncTube-QSwitcher

Quality switcher plugin for SyncTube
JavaScript
4
star
14

TwitchSpeedVideoCreator

Twitch.tv past broadcasts downloader with ability to speed up videos
Java
3
star
15

favis-bot

Tag your favorite stickers and send them in inline mode
Kotlin
2
star
16

DonNUEdgeDetector

Detect edges from camera with OpenCV library
C++
2
star
17

Turrets

Network game
Java
2
star
18

JMethodRearranger

Java methods organizer
Java
2
star
19

JTicTacToe

Java TicTacToe game.
Java
2
star
20

aScheduler

Программа редактирования расписания
Java
2
star
21

University-Java

Лабораторные работы по курсу "Технологии Программной Инженерии" Донецкого Национального Университета
Java
1
star
22

Rouge-et-Noir

Пасьянс Rouge-et-Noir
C#
1
star
23

aNNiMON

1
star