2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ちょっとプログラム載せてみる。

2
Last updated at Posted at 2014-11-26

とりあえずJavaでいいかな。

この前、JDK8から導入されたラムダ式の勉強するのに書いたプログラム載っけます。

import java.util.List;
import java.util.ArrayList;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        final List<PriceListElement> priceList = new ArrayList<PriceListElement>();
        priceList.add(new PriceListElement(1, "apple", 120));
        priceList.add(new PriceListElement(2, "orage", 88));
        priceList.add(new PriceListElement(3, "water melon", 250));
        priceList.add(new PriceListElement(4, "melon", 500));

        Stream<PriceListElement> result = priceList.stream().filter(e -> e.getPrice() >= 100);
        print(result);
        result = priceList.stream().filter(e -> e.getName().contains("melon"));
        print(result);
    }

    public static void print(Stream<PriceListElement> list) {
        System.out.println("-----");

        for(Object e : list.toArray()) {
            System.out.println(e);
        }
    }
}

/*
参考
■Java 8はラムダ式でここまで変わる(1):初心者のためのJavaラムダ式入門とJDKのインストール、IDEの環境構築 (1/4) - @IT
<http://www.atmarkit.co.jp/ait/articles/1402/18/news010.html>
*/
public class PriceListElement {
    private int id;
    private String name;
    private int price;

    public void setId(int id) {
        this.id = id;
    }

    public int getId() {
        return id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return this.name;
    }

    public void setPrice() {
        this.price = price;
    }

    public int getPrice() {
        return this.price;
    }

    public PriceListElement(int id, String name, int price) {
        this.id = id;
        this.name = name;
        this.price = price;
    }

    public String toString() {
        return id + ", " + name + ", " + price;
    }
}

もうちょっとEclipseっぽい色合いになってくれるとすごくうれしいんだけど、まあ、これで十分かな。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?