-
-
Save anonymous/099320997c8b4d62dcdafc2663f87175 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.user01.androidjava8streamtest; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.util.Log; | |
import java.util.ArrayList; | |
import java.util.List; | |
import static java.util.Comparator.*; | |
public class MainActivity extends AppCompatActivity { | |
class Person { | |
public Person(String name, Integer age){ | |
this.name = name; | |
this.age = age; | |
} | |
public String name; | |
public String getName() { | |
return name; | |
} | |
public Integer age; | |
public Integer getAge() { | |
return age; | |
} | |
} | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
List<Person> persons = new ArrayList<>(); | |
persons.add(new Person("a", 3)); | |
persons.add(new Person("b", 2)); | |
persons.add(new Person("b", 4)); | |
persons.add(new Person("c", 1)); | |
persons.sort(comparing(Person::getName, reverseOrder()).thenComparing(Person::getAge)); | |
for(Person p : persons) { | |
Log.d("tag", p.name + p.age); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment