Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Comparator;
- import java.util.Iterator;
- import java.util.List;
- public class Zadanie4 {
- public static void main(String[] args) {
- List<Osoba> osoby = new ArrayList<>();
- osoby.add(new Osoba("Jan", "Kowalski", 19));
- osoby.add(new Osoba("Ania", "Milian", 19));
- osoby.add(new Osoba("Artur", "Kowal", 19));
- osoby.add(new Osoba("Beata", "Olech", 19));
- Iterator<Osoba> i = osoby.iterator();
- while (i.hasNext()) {
- Osoba o = i.next();
- if (o.getImię().startsWith("A"))
- {
- i.remove();
- }
- }
- for(Osoba o : osoby){
- System.out.println(o.getImię()+ " " + o.getNazwisko()+ " " + o.getWiek() );
- }
- }
- }
- class Osoba implements Comparable<Osoba> {
- private String imię;
- private String nazwisko;
- private int wiek;
- public Osoba(String imię, String nazwisko, int wiek) {
- this.imię = imię;
- this.nazwisko = nazwisko;
- this.wiek = wiek;
- }
- public String getImię() {
- return imię;
- }
- public String getNazwisko() {
- return nazwisko;
- }
- public int getWiek() {
- return wiek;
- }
- @Override
- public int compareTo(Osoba o) {
- return (o.getWiek() - this.getWiek());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement