Übungen
parent
2bdf796ae3
commit
e2f05fe419
|
@ -0,0 +1,93 @@
|
|||
package Testate.Stream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
public class Finanzanalyse {
|
||||
|
||||
private static ArrayList<Transaction> tran = new ArrayList<>();
|
||||
|
||||
public static void main(String[] args) throws FileNotFoundException {
|
||||
addTran();
|
||||
|
||||
// Eine gefilterte Liste mit allen Überweisungen in einer bestimmten Währung.
|
||||
Map<String, List<Transaction>> aufgabe1 = tran.parallelStream()
|
||||
.filter(t -> t.getCurrency().equalsIgnoreCase("EUR"))
|
||||
.collect(Collectors.groupingBy(t -> t.getCurrency(), Collectors.toCollection(ArrayList::new)));
|
||||
// aufgabe1.forEach((a,b) -> System.out.println(a +" " + b));
|
||||
|
||||
// Anzahl und Anteil der Überweisungen, die ins Ausland gegangen sind
|
||||
Map<Transaction, Long> aufgabe2 = tran.parallelStream().filter(t -> t.getRecCountry() != null)
|
||||
.collect(Collectors.groupingBy(t -> t, Collectors.counting()));
|
||||
// aufgabe2.forEach((a,b) -> System.out.println(a + " " + b));
|
||||
Long aufgabe2_2 = tran.parallelStream().filter(t -> t.getRecCountry() != null).collect(Collectors.counting());
|
||||
|
||||
// Gesamtsumme der Überweisungen in den jeweiligen Währungen.
|
||||
Long summe = tran.stream().filter(t -> t.getCurrency().equalsIgnoreCase("USD")).collect(Collectors.counting());
|
||||
// System.out.println(summe);
|
||||
|
||||
// Gesamtmenge des (ausgehend) überwiesenen Gelds für einen gegebenen Sender und
|
||||
// eine gegebene Währung.
|
||||
Double gesamtmenge = tran.stream().filter(t -> t.getSender().getName().equalsIgnoreCase("Elizabeth Bernard"))
|
||||
.filter(t -> t.getCurrency().equalsIgnoreCase("EUR")).map(t -> t.getAmount())
|
||||
.reduce(0.0, (i, j) -> i + j);
|
||||
//System.out.println(gesamtmenge);
|
||||
|
||||
// Die fünf höchsten Geldbeträge, die überwiesen worden sind (Währung kann
|
||||
// ignoriert werden).
|
||||
|
||||
ArrayList<Transaction> maxGeldbeträge = tran.stream()
|
||||
.sorted((o1,o2) -> Double.compare(o2.getAmount(), o1.getAmount()))
|
||||
.limit(5)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
// maxGeldbeträge.forEach(System.out::println);
|
||||
|
||||
//Die zehn Konten, die an den meisten Transaktionen beteiligt sind.
|
||||
|
||||
String[] array = {"H","A","H","A"};
|
||||
Map<String, List<String>> map = Stream.of(array)
|
||||
.collect(Collectors.groupingBy(Function.identity()));
|
||||
|
||||
//map.forEach((a,b) -> System.out.println(a +" " +b));
|
||||
// 5) Holly Wood ausgehend an USD
|
||||
List<Transaction> beträge = tran.stream()
|
||||
.filter(tr -> "Holly Wood".equals(tr.getSender().getName()))
|
||||
.filter(tr -> "USD".equals(tr.getCurrency()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
System.out.println(beträge);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void addTran() throws FileNotFoundException, NumberFormatException {
|
||||
File file = new File(
|
||||
"C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\streams\\synthetic_data.csv");
|
||||
Scanner sc = new Scanner(file);
|
||||
|
||||
sc.nextLine();
|
||||
while (sc.hasNext()) {
|
||||
String line = sc.nextLine();
|
||||
String[] cols = line.split(",");
|
||||
|
||||
Account sender = new Account(cols[0], cols[1]);
|
||||
Account receiver = new Account(cols[2], cols[3]);
|
||||
|
||||
tran.add(new Transaction(sender, receiver, Double.parseDouble(cols[4]), cols[5],
|
||||
(cols.length == 6) ? null : cols[6]));
|
||||
}
|
||||
sc.close();
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<Transaction> getTran() {
|
||||
return tran;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package Testate.Stream;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Studenten und Prüfungen erstellen
|
||||
Student student1 = new Student("Lax Mustermann", "Berlin", "Informatik");
|
||||
student1.addPrüfung(new Prüfung("Mathe", 5, 1, 3.0));
|
||||
student1.addPrüfung(new Prüfung("Programmierung", 5, 1, 4.5));
|
||||
|
||||
Student student2 = new Student("Anna Müller", "Hamburg", "Maschinenbau");
|
||||
student2.addPrüfung(new Prüfung("Mechanik", 5, 1, 2.0));
|
||||
student2.addPrüfung(new Prüfung("Thermodynamik", 5, 2, 1.7));
|
||||
|
||||
Student student3 = new Student("Lisa Schmidt", "München", "Informatik");
|
||||
student3.addPrüfung(new Prüfung("Datenbanken", 5, 3, 3.5));
|
||||
student3.addPrüfung(new Prüfung("Betriebssysteme", 5, 4, 5.0));
|
||||
|
||||
Student student4 = new Student("Aisa Schmidt", "München", "Cyber");
|
||||
student4.addPrüfung(new Prüfung("Datenbanken", 5, 3, 3.5));
|
||||
student4.addPrüfung(new Prüfung("Betriebssysteme", 5, 4, 5.0));
|
||||
|
||||
Student studen5 = new Student("Aisa Schmidt", "München", "Informatik");
|
||||
studen5.addPrüfung(new Prüfung("Datenbanken", 5, 3, 3.5));
|
||||
studen5.addPrüfung(new Prüfung("Betriebssysteme", 5, 4, 5.0));
|
||||
|
||||
// Liste von Studenten
|
||||
List<Student> studenten = new ArrayList<>();
|
||||
studenten.add(student1);
|
||||
studenten.add(student2);
|
||||
studenten.add(student3);
|
||||
studenten.add(student4);
|
||||
studenten.add(studen5);
|
||||
|
||||
//Alle Prüfungen mit ihrem Namen, dem Semester, der Note und Namen des Studis ausgeben
|
||||
|
||||
Map<Student,List<Prüfung>> aufgabe1 = studenten.stream()
|
||||
.collect(Collectors.toMap(st -> st,st -> st.getPrüfungen()));
|
||||
//aufgabe1.forEach((a,b) ->System.out.println(a + " " + b));
|
||||
|
||||
//Notenschnitt
|
||||
Map<Student, Double> note = studenten.stream()
|
||||
.collect(Collectors.toMap(st -> st, n -> n.getPrüfungen().stream().collect(Collectors.averagingDouble(t -> t.getNote()))));
|
||||
|
||||
//note.forEach((a,b) -> System.out.println(a +" " +b));
|
||||
|
||||
|
||||
Map<Student, Double> note2 = studenten.stream()
|
||||
.collect(Collectors.toMap(
|
||||
st -> st, // Direkte Verwendung des Studenten als Schlüssel
|
||||
student -> student.getPrüfungen().stream()
|
||||
.mapToDouble(Prüfung::getNote) // Direkte Nutzung von mapToDouble
|
||||
.average()
|
||||
.orElse(0.0) // Falls keine Prüfungen vorhanden sind, Standardwert 0.0
|
||||
));
|
||||
//Alle Studenten ausgeben, die eine Prüfung nicht bestanden haben
|
||||
// studenten.stream()
|
||||
// .filter(st -> st.getPrüfungen().stream().anyMatch(p -> p.getNote() >= 5))
|
||||
// .forEach(st -> System.out.println(st.toString()));
|
||||
|
||||
|
||||
Map<String, Double> durchschnittProStudiengang = studenten.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
Student::getStudiengang,
|
||||
Collectors.averagingDouble(student -> student.getPrüfungen().stream()
|
||||
.mapToDouble(Prüfung::getNote)
|
||||
.average()
|
||||
.orElse(0.0))
|
||||
|
||||
));
|
||||
|
||||
durchschnittProStudiengang.forEach((a,b) -> System.out.println(a + " " + b));
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,179 @@
|
|||
package Testate.Stream;
|
||||
|
||||
import static java.util.Map.Entry.comparingByValue;
|
||||
import static java.util.stream.Collectors.counting;
|
||||
import static java.util.stream.Collectors.groupingBy;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.example.domain.Movie;
|
||||
|
||||
|
||||
public class Movie {
|
||||
private int id;
|
||||
private String title;
|
||||
private int year;
|
||||
private String imdb;
|
||||
private ArrayList<Genre> genres;
|
||||
private ArrayList<Director> directors;
|
||||
|
||||
{
|
||||
genres = new ArrayList<>();
|
||||
directors = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Movie(int id, String title, int year, String imdb) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.year = year;
|
||||
this.imdb = imdb;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public int getYear() {
|
||||
return year;
|
||||
}
|
||||
|
||||
public String getImdb() {
|
||||
return imdb;
|
||||
}
|
||||
|
||||
public ArrayList<Genre> getGenres() {
|
||||
return genres;
|
||||
}
|
||||
|
||||
public ArrayList<Director> getDirectors() {
|
||||
return directors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Movie [title=" + title + ", year=" + year + " ,Directors= " + directors + "Genres= " +genres + " ]";
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// Genres
|
||||
Genre genre1 = new Genre(1, "Action");
|
||||
Genre genre2 = new Genre(2, "Drama");
|
||||
Genre genre3 = new Genre(3, "Comedy");
|
||||
|
||||
// Directors
|
||||
Director director1 = new Director(1, "Christopher Nolan", "imdb.com/nolan");
|
||||
Director director2 = new Director(2, "Quentin Tarantino", "imdb.com/tarantino");
|
||||
Director director3 = new Director(3, "Steven Spielberg", "imdb.com/spielberg");
|
||||
|
||||
// Movies
|
||||
Movie movie1 = new Movie(1, "Inception", 2010, "imdb.com/inception");
|
||||
movie1.getGenres().add(genre1);
|
||||
movie1.getGenres().add(genre2);
|
||||
movie1.getDirectors().add(director1);
|
||||
|
||||
Movie movie2 = new Movie(2, "Pulp Fiction", 1993, "imdb.com/pulpfiction");
|
||||
movie2.getGenres().add(genre2);
|
||||
movie2.getGenres().add(genre3);
|
||||
movie2.getDirectors().add(director2);
|
||||
|
||||
Movie movie3 = new Movie(3, "Pulp Fiction", 1993, "imdb.com/jurassicpark");
|
||||
movie3.getGenres().add(genre1);
|
||||
movie3.getDirectors().add(director1);
|
||||
|
||||
ArrayList<Movie> movies = new ArrayList<>();
|
||||
movies.add(movie1);
|
||||
movies.add(movie2);
|
||||
movies.add(movie3);
|
||||
//movies.forEach(System.out::println);
|
||||
|
||||
//Finde die Anzahl der Filme jedes Regisseurs.
|
||||
Map<String,Long> anzahl = movies.stream()
|
||||
.flatMap(s -> s.getDirectors().stream())
|
||||
.map(r -> r.getName())
|
||||
.collect(Collectors.groupingBy(name -> name, Collectors.counting()));
|
||||
//anzahl.forEach((a,b) -> System.out.println(a + " " +b));
|
||||
|
||||
//Finde die Liste der Filme, die nur die Genres "Drama" und "Komödie" haben.
|
||||
|
||||
List<Movie> aufgabe7 = movies.stream()
|
||||
.filter(f -> f.getGenres().stream().anyMatch(fil -> fil.getName().equalsIgnoreCase("Drama")))
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
// System.out.println(aufgabe7);
|
||||
|
||||
var maxMovieCountByYear =
|
||||
movies.stream()
|
||||
.collect(groupingBy(Movie::getYear,counting()))
|
||||
.entrySet()
|
||||
.stream()
|
||||
.max(comparingByValue());
|
||||
maxMovieCountByYear.ifPresent(System.out::println);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class Genre {
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
public Genre() {
|
||||
}
|
||||
|
||||
public Genre(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Genre [id=" + id + ", name=" + name + "]";
|
||||
}
|
||||
}
|
||||
|
||||
class Director {
|
||||
private int id;
|
||||
private String name;
|
||||
private String imdb;
|
||||
|
||||
public Director() {
|
||||
}
|
||||
|
||||
public Director(int id, String name, String imdb) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.imdb = imdb;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getImdb() {
|
||||
return imdb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Director [id=" + id + ", name=" + name + ", imdb=" + imdb + "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,178 @@
|
|||
package Testate.Stream;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Ort implements Comparable<Ort> {
|
||||
|
||||
String name;
|
||||
int postleitzahl;
|
||||
double länge;
|
||||
double breite;
|
||||
|
||||
public Ort(String name, int postleitzahl, double länge, double breite) {
|
||||
this.name = name;
|
||||
this.postleitzahl = postleitzahl;
|
||||
this.länge = länge;
|
||||
this.breite = breite;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getPostleitzahl() {
|
||||
return postleitzahl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setPostleitzahl(int postleitzahl) {
|
||||
this.postleitzahl = postleitzahl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public double getLänge() {
|
||||
return länge;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setLänge(double länge) {
|
||||
this.länge = länge;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public double getBreite() {
|
||||
return breite;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setBreite(double breite) {
|
||||
this.breite = breite;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Ort [name=" + name + ", postleitzahl=" + postleitzahl + ", länge=" + länge + ", breite=" + breite + "]";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compareTo(Ort o) {
|
||||
return Integer.compare(o.postleitzahl, this.postleitzahl);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Ort[] orte2 = new Ort[5];
|
||||
orte2[1] = new Ort("Hamburg", 20095, 9.9937,0);
|
||||
orte2[0] = new Ort("Berlin", 10115, 13.405, 52.52);
|
||||
|
||||
orte2[2] = new Ort("München", 80331, 11.5755, 10);
|
||||
orte2[3] = new Ort("Köln", 50667, 6.9603, 50.9375);
|
||||
orte2[4] = new Ort("Frankfurt", 60311, 8.6821, 50.1109);
|
||||
|
||||
|
||||
bubbleSort(orte2);
|
||||
for (Ort o : orte2)
|
||||
System.out.println(o.toString());
|
||||
}
|
||||
|
||||
public static void bubbleSort(Ort[] orte) {
|
||||
|
||||
for (int i = 0 ; i < orte.length-1; i++)
|
||||
for(int j = 0; j < orte.length -1; j++)
|
||||
if (orte[j].compareTo(orte[j+1]) > 0) {
|
||||
Ort tem = orte[j];
|
||||
orte[j] = orte[j+1];
|
||||
orte[j+1] = tem;
|
||||
}
|
||||
}
|
||||
|
||||
public static void insertionSort(Ort[] orte) {
|
||||
int n = orte.length;
|
||||
|
||||
for (int i = 1; i < n; i++) {
|
||||
Ort key = orte[i];
|
||||
int j = i - 1;
|
||||
|
||||
// Verschiebe Elemente, die größer als der Schlüssel sind, um Platz zu schaffen
|
||||
while (j >= 0 && orte[j].postleitzahl < key.postleitzahl) {
|
||||
orte[j + 1] = orte[j];
|
||||
j--;
|
||||
}
|
||||
|
||||
// Setze den Schlüssel an die richtige Stelle
|
||||
orte[j + 1] = key;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static LinkedList<Ort> findOrte(Ort[] orte) {
|
||||
Stream<Ort> st = Stream.of(orte);
|
||||
|
||||
LinkedList<Ort> treffer = st.parallel().filter(o -> o.getBreite() > 0)
|
||||
.collect(Collectors.toCollection(LinkedList::new));
|
||||
|
||||
return treffer;
|
||||
}
|
||||
|
||||
public static void sort(Ort[] orte) {
|
||||
|
||||
for (int i = 0; i < orte.length; i++) {
|
||||
int merker = i;
|
||||
|
||||
for (int j = i + 1; j < orte.length; j++)
|
||||
if (orte[j].compareTo(orte[merker]) < 0)
|
||||
merker = j;
|
||||
|
||||
Ort tem = orte[merker];
|
||||
orte[merker] = orte[i];
|
||||
orte[i] = tem;
|
||||
}
|
||||
}
|
||||
|
||||
public static void sortComparator(Ort[] orte, Comparator<Ort> sort) {
|
||||
sort = new SortOrte();
|
||||
for (int i = 0; i < orte.length; i++) {
|
||||
int merker = i;
|
||||
|
||||
for (int j = i + 1; j < orte.length; j++)
|
||||
if (sort.compare(orte[j], orte[merker]) > 0)
|
||||
merker = j;
|
||||
|
||||
Ort tem = orte[merker];
|
||||
orte[merker] = orte[i];
|
||||
orte[i] = tem;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class SortOrte implements Comparator<Ort>{
|
||||
|
||||
@Override
|
||||
public int compare(Ort o1, Ort o2) {
|
||||
return o2.name.compareTo(o1.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package Testate.Stream;
|
||||
|
||||
public class Prüfung {
|
||||
private String name;
|
||||
private int ectsZahl;
|
||||
private int semester;
|
||||
private double note;
|
||||
|
||||
// Konstruktor
|
||||
public Prüfung(String name, int ectsZahl, int semester, double note) {
|
||||
this.name = name;
|
||||
this.ectsZahl = ectsZahl;
|
||||
this.semester = semester;
|
||||
this.note = note;
|
||||
}
|
||||
|
||||
// Getter und Setter
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getEctsZahl() {
|
||||
return ectsZahl;
|
||||
}
|
||||
|
||||
public void setEctsZahl(int ectsZahl) {
|
||||
this.ectsZahl = ectsZahl;
|
||||
}
|
||||
|
||||
public int getSemester() {
|
||||
return semester;
|
||||
}
|
||||
|
||||
public void setSemester(int semester) {
|
||||
this.semester = semester;
|
||||
}
|
||||
|
||||
public double getNote() {
|
||||
return note;
|
||||
}
|
||||
|
||||
public void setNote(double note) {
|
||||
this.note = note;
|
||||
}
|
||||
|
||||
// Methode, um zu prüfen, ob die Prüfung bestanden ist
|
||||
public boolean istBestanden() {
|
||||
return note <= 4.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Prüfung{" +
|
||||
"name='" + name + '\'' +
|
||||
", ectsZahl=" + ectsZahl +
|
||||
", semester=" + semester +
|
||||
", note=" + note +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package Testate.Stream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SortAlgorithm {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int[] arr = {60,40,50,30,10,20};
|
||||
SelectionSort(arr);
|
||||
|
||||
for (int i : arr)
|
||||
System.out.println(i);
|
||||
|
||||
ArrayList<Integer> array = new ArrayList<>();
|
||||
array.add(10);
|
||||
array.add(4);
|
||||
array.add(5);
|
||||
array.add(6);
|
||||
SelectionSort2(array);
|
||||
System.out.println(array);
|
||||
}
|
||||
|
||||
|
||||
public static void SelectionSort(int[] array) {
|
||||
int n = array.length;
|
||||
for (int i = 0; i < n - 1; i++) {
|
||||
int minIndex = i;
|
||||
for (int j = i + 1; j < n; j++) {
|
||||
if (array[j] > array[minIndex]) {
|
||||
minIndex = j;
|
||||
}
|
||||
}
|
||||
|
||||
// Tausche das kleinste Element mit dem ersten Element des unsortierten Teils
|
||||
int temp = array[minIndex];
|
||||
array[minIndex] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SelectionSort2(ArrayList<Integer> array) {
|
||||
int n = array.size();
|
||||
for (int i = 0; i < n - 1; i++) {
|
||||
int minIndex = i;
|
||||
for (int j = i + 1; j < n; j++) {
|
||||
if (array.get(j).compareTo(array.get(minIndex)) > 0 ) {
|
||||
minIndex = j;
|
||||
}
|
||||
}
|
||||
|
||||
// Tausche das kleinste Element mit dem ersten Element des unsortierten Teils
|
||||
int temp = array.get(minIndex);
|
||||
array.add(array.get(i));
|
||||
array.add(temp);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package Testate.Stream;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Student implements Comparable<Student> {
|
||||
private String name;
|
||||
private String wohnort;
|
||||
private String studiengang;
|
||||
private List<Prüfung> prüfungen;
|
||||
|
||||
// Konstruktor
|
||||
public Student(String name, String wohnort, String studiengang) {
|
||||
this.name = name;
|
||||
this.wohnort = wohnort;
|
||||
this.studiengang = studiengang;
|
||||
this.prüfungen = new ArrayList<>();
|
||||
}
|
||||
|
||||
// Getter und Setter
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getWohnort() {
|
||||
return wohnort;
|
||||
}
|
||||
|
||||
public void setWohnort(String wohnort) {
|
||||
this.wohnort = wohnort;
|
||||
}
|
||||
|
||||
public String getStudiengang() {
|
||||
return studiengang;
|
||||
}
|
||||
|
||||
public void setStudiengang(String studiengang) {
|
||||
this.studiengang = studiengang;
|
||||
}
|
||||
|
||||
public List<Prüfung> getPrüfungen() {
|
||||
return prüfungen;
|
||||
}
|
||||
|
||||
// Methoden
|
||||
public void addPrüfung(Prüfung prüfung) {
|
||||
this.prüfungen.add(prüfung);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Student{" +
|
||||
"name='" + name + '\'' +
|
||||
", wohnort='" + wohnort + '\'' +
|
||||
", studiengang='" + studiengang + '\'' +
|
||||
", prüfungen=" + prüfungen +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Student o) {
|
||||
// Zuerst nach Studiengang sortieren
|
||||
int nameVergleich = this.name.compareTo(o.getName());
|
||||
|
||||
// Wenn die Studiengänge gleich sind, nach Name sortieren
|
||||
if (nameVergleich == 0)
|
||||
return this.studiengang.compareTo(o.getStudiengang());
|
||||
|
||||
return nameVergleich;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package Testate.Stream.Studentt;
|
||||
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
// Prüfungen erstellen
|
||||
Prüfung prüfung1 = new Prüfung(2.3f, true); // Grundstudium
|
||||
Prüfung prüfung2 = new Prüfung(3.7f, true); // Grundstudium
|
||||
Prüfung prüfung3 = new Prüfung(1.7f, false); // Kein Grundstudium
|
||||
Prüfung prüfung4 = new Prüfung(4.0f, true); // Grundstudium
|
||||
Prüfung prüfung5 = new Prüfung(2.0f, false); // Kein Grundstudium
|
||||
|
||||
// Student erstellen
|
||||
Student student1 = new Student();
|
||||
student1.setpList(prüfung1);
|
||||
student1.setpList(prüfung2);
|
||||
student1.setpList(prüfung3);
|
||||
|
||||
Student student2 = new Student();
|
||||
student2.setpList(prüfung4);
|
||||
student2.setpList(prüfung5);
|
||||
|
||||
ArrayList<Student> st = new ArrayList<>();
|
||||
st.add(student1);
|
||||
st.add(student2);
|
||||
|
||||
Map<Student, Double> t =
|
||||
st.stream()
|
||||
.collect(Collectors.toMap(stu -> stu, stu -> stu.getpList().stream().mapToDouble(p -> p.getNote()).average().orElse(0.0)));
|
||||
|
||||
double result = berechene(st);
|
||||
System.out.println(result);
|
||||
|
||||
}
|
||||
|
||||
public static double berechene(ArrayList<Student> st ) {
|
||||
Double result = st.stream()
|
||||
.flatMap(p -> p.pList.stream())
|
||||
.filter(p -> p.isIstGrundStudium())
|
||||
.mapToDouble(p -> p.getNote())
|
||||
.average().orElse(0.0);
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package Testate.Stream.Studentt;
|
||||
|
||||
|
||||
public class Prüfung {
|
||||
private float note;
|
||||
private boolean istGrundStudium;
|
||||
|
||||
public Prüfung(float note, boolean istGrundStudium) {
|
||||
this.note = note;
|
||||
this.istGrundStudium = istGrundStudium;
|
||||
}
|
||||
|
||||
public float getNote() {
|
||||
return note;
|
||||
}
|
||||
|
||||
public boolean isIstGrundStudium() {
|
||||
return istGrundStudium;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Prüfung [note=" + note + ", istGrundStudium=" + istGrundStudium + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package Testate.Stream.Studentt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Student {
|
||||
ArrayList<Prüfung> pList;
|
||||
|
||||
public Student() {
|
||||
|
||||
this.pList = new ArrayList<>();
|
||||
}
|
||||
|
||||
public ArrayList<Prüfung> getpList() {
|
||||
return pList;
|
||||
}
|
||||
|
||||
public void setpList(Prüfung prüfung) {
|
||||
this.pList.add(prüfung);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package Testate.Stream;
|
||||
|
||||
public class Transaction {
|
||||
private Account sender, receiver;
|
||||
private double amount;
|
||||
private String currency;
|
||||
private String recCountry;
|
||||
|
||||
public Transaction(Account sender, Account receiver, double amount, String currency, String recCountry) {
|
||||
super();
|
||||
this.sender = sender;
|
||||
this.receiver = receiver;
|
||||
this.amount = amount;
|
||||
this.currency = currency;
|
||||
this.recCountry = recCountry;
|
||||
}
|
||||
|
||||
public Account getSender() {
|
||||
return sender;
|
||||
}
|
||||
public Account getReceiver() {
|
||||
return receiver;
|
||||
}
|
||||
public double getAmount() {
|
||||
return amount;
|
||||
}
|
||||
public String getCurrency() {
|
||||
return currency;
|
||||
}
|
||||
public String getRecCountry() {
|
||||
return recCountry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Transaction [sender=" + sender + ", receiver=" + receiver + ", amount=" + amount + ", currency="
|
||||
+ currency + ", recCountry=" + recCountry + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class Account {
|
||||
private String name;
|
||||
private String number;
|
||||
|
||||
public Account(String name, String number) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Account [name=" + name + ", number=" + number + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,10 +1,11 @@
|
|||
package VorlesungsFolien.SortierenmitComparatoren_Comparable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class Main {
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
//1.Ungeordnet//
|
||||
|
@ -55,16 +56,10 @@ public class Main {
|
|||
|
||||
// Elemente werden alphabetisch sortiert
|
||||
System.out.println("Sorted Set: " + sortedSet);
|
||||
|
||||
|
||||
TreeSet<String> ts = new TreeSet<>();
|
||||
ts.add("X");
|
||||
ts.add("B");
|
||||
ts.add("A");
|
||||
ts.add("H");
|
||||
for (String s : ts)
|
||||
System.out.println(s);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,31 +1,35 @@
|
|||
package oop.Enumeration;
|
||||
import java.util.EnumSet;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public enum EnumMethods {
|
||||
MONTAG, DIENSTAG, MITTWOCH, DONNERSTAG, FREITAG, SAMSTAG, SONNTAG;
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
// gibt mir die Index meiner Konstante zurück
|
||||
System.out.println(EnumMethods.DIENSTAG.ordinal());
|
||||
System.out.println(EnumMethods.DIENSTAG.ordinal());// 1
|
||||
|
||||
//vergleicht zwei enum-Konstanten basierend auf ihrer Reihenfolge
|
||||
System.out.println(EnumMethods.DIENSTAG.compareTo(EnumMethods.DONNERSTAG));
|
||||
System.out.println(EnumMethods.DIENSTAG.compareTo(EnumMethods.DONNERSTAG));// -2
|
||||
|
||||
// gibt true oder false zurück
|
||||
System.out.println(EnumMethods.DIENSTAG.toString() == "DIENSTAG");
|
||||
System.out.println(EnumMethods.DIENSTAG.toString() == "DIENSTAG"); // true
|
||||
|
||||
// gibt true oder false zurück
|
||||
System.out.println(EnumMethods.DIENSTAG.name() == "DIENSTAG");
|
||||
System.out.println(EnumMethods.DIENSTAG.name() == "DIENSTAG"); // true
|
||||
|
||||
// gibt der Name der Kosntant zurück
|
||||
System.out.println(EnumMethods.valueOf("DONNERSTAG"));
|
||||
EnumMethods t = EnumMethods.valueOf("donnerstag".toUpperCase()); // DONNERSTAG
|
||||
System.out.println(EnumMethods.valueOf("DONNERSTAG")); // DONNERSTAG
|
||||
|
||||
// gibt mir alle Konstante zurück
|
||||
for (EnumMethods test: EnumMethods.values()) {
|
||||
System.out.print(test + " ");
|
||||
if (test == EnumMethods.DIENSTAG)
|
||||
EnumMethods[] test = EnumMethods.values(); // als Array
|
||||
Stream<EnumMethods> te = Stream.of(test); // Stream of Enunms
|
||||
|
||||
|
||||
for (EnumMethods e: test) {
|
||||
System.out.print(e.toString() + " ");
|
||||
if (e == EnumMethods.DIENSTAG)
|
||||
System.out.print(EnumMethods.values() + " ");
|
||||
}
|
||||
System.out.println(EnumMethods.values()[0] + "Einzelene Konstant");
|
||||
|
@ -53,6 +57,7 @@ public enum EnumMethods {
|
|||
System.out.println(range);
|
||||
|
||||
|
||||
System.out.println("hier");
|
||||
EnumSet<EnumMethods> noneOf = EnumSet.noneOf(EnumMethods.class);
|
||||
noneOf.add(DIENSTAG);
|
||||
noneOf.addAll(noneOf);
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package oop.Enumeration;
|
||||
|
||||
import java.util.EnumMap;
|
||||
|
||||
enum Farbe {
|
||||
ROT(255, 0, 0), GRÜN(0, 255, 0), BLAU(0, 0, 255);
|
||||
|
||||
private final int r;
|
||||
private final int g;
|
||||
private final int b;
|
||||
private Farbe(int r, int g, int b) {
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public int getR() {
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
public int getG() {
|
||||
return g;
|
||||
}
|
||||
|
||||
public int getB() {
|
||||
return b;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class Enummap {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// EnumMap initialisieren
|
||||
EnumMap<Farbe, String> test = new EnumMap<>(Farbe.class);
|
||||
|
||||
test.put(Farbe.GRÜN, "Hose");
|
||||
test.put(Farbe.BLAU, "Mütze");
|
||||
test.put(Farbe.ROT, "sommerHose");
|
||||
test.put(Farbe.ROT, "WinterHose");
|
||||
test.put(Farbe.BLAU, "sommerHose");
|
||||
|
||||
test.forEach((a,b) -> System.out.println(a + " " + b));
|
||||
|
||||
Farbe getFarbe = Farbe.valueOf(args[0].toUpperCase());
|
||||
System.out.println("Gewählte Farbe: " + getFarbe.name());
|
||||
|
||||
}
|
||||
}
|
|
@ -1,20 +1,20 @@
|
|||
package streams;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Reduce_Methode {
|
||||
static String str = "dds";
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
List<Integer> al = Arrays.asList(3,7,2,1,8,4,5);
|
||||
al.forEach(i -> System.out.println(i + str));
|
||||
|
||||
|
||||
// System.out.println(al.stream().reduce(0, (i,j) -> i+j));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
package streams;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Reduce_Methode {
|
||||
static String str = "dds";
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
List<Integer> al = Arrays.asList(3,7,2,1,8,4,5);
|
||||
|
||||
System.out.println(al.stream().reduce((i,j) -> i+j));
|
||||
al.forEach(null);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package streams.übungen.Animal;
|
||||
package streams.Testate;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -48,24 +48,7 @@ public abstract class Animal {
|
|||
animals.add(new Spider());
|
||||
animals.add(new Spider());
|
||||
|
||||
//animal with the highest number of legs
|
||||
Animal a = animals.stream()
|
||||
.max(Comparator.comparingInt(d -> d.getLegs()))
|
||||
.orElse(null);
|
||||
|
||||
|
||||
//Q.5) Find the total number of legs
|
||||
int max = animals.stream()
|
||||
.map(t -> t.getLegs())
|
||||
.mapToInt(Integer::intValue)
|
||||
.sum();
|
||||
|
||||
//Group the animals by their number of legs
|
||||
Map<Animal, Long> animalMap = animals.stream()
|
||||
.collect(Collectors.groupingBy(d -> d, Collectors.counting()));
|
||||
|
||||
animalMap.forEach((animal, count) ->
|
||||
System.out.println(animal + " -> " + count + " mal"));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package streams.übungen;
|
||||
package streams.Testate;
|
||||
|
||||
public class City {
|
||||
private int id;
|
|
@ -1,4 +1,4 @@
|
|||
package streams.übungen;
|
||||
package streams.Testate;
|
||||
|
||||
import java.util.*;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package streams.übungen;
|
||||
package streams.Testate;
|
||||
|
||||
import java.util.*;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package streams.übungen;
|
||||
package streams.Testate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package streams.Testate;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
ArrayList<Integer> arr = new ArrayList<>();
|
||||
arr.add(1);
|
||||
arr.add(2);
|
||||
arr.add(4);
|
||||
arr.add(19);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package streams.übungen;
|
||||
package streams.Testate;
|
||||
|
||||
public class Movie {
|
||||
private int id;
|
|
@ -1,4 +1,4 @@
|
|||
package streams.übungen;
|
||||
package streams.Testate;
|
||||
|
||||
import java.util.*;
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package streams.Testate;
|
||||
|
||||
public class RegistrierungDTO {
|
||||
|
||||
private final String vorname;
|
||||
private final String nachname;
|
||||
private final boolean istAdmin;
|
||||
private final boolean vergünstigungsberechtigt;
|
||||
|
||||
public RegistrierungDTO(String vorname, String nachname,boolean istAdmin , boolean vergünstigungsberechtigt ) {
|
||||
this.vorname = vorname;
|
||||
this.nachname = nachname;
|
||||
this.istAdmin = istAdmin;
|
||||
this.vergünstigungsberechtigt = vergünstigungsberechtigt;
|
||||
}
|
||||
|
||||
public String getvorname() {
|
||||
return vorname;
|
||||
}
|
||||
|
||||
public String getnachname() {
|
||||
return nachname;
|
||||
}
|
||||
|
||||
public boolean istAdmin() {
|
||||
return istAdmin;
|
||||
}
|
||||
|
||||
public boolean vergünstigungsberechtigt() {
|
||||
return vergünstigungsberechtigt;
|
||||
}
|
||||
|
||||
public boolean equal(RegistrierungDTO o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "....";
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
record RegistrierungDTO2(String vorname, String nachname, boolean istAdmin,boolean vergünstigungsberechtigt ) {}
|
|
@ -1,138 +0,0 @@
|
|||
package streams.übungen;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
countryTest();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void countryTest() {
|
||||
CountryTest test = new CountryTest();
|
||||
//Q.2) Find the most populated city of each country
|
||||
Map<Country,City> q2 = test.test
|
||||
.stream()
|
||||
.parallel()
|
||||
.collect(Collectors.toMap(
|
||||
country -> country,
|
||||
country -> country.getCities().stream()
|
||||
.max(Comparator.comparingInt(t -> t.getPopulation()))
|
||||
.orElse(null)
|
||||
));
|
||||
|
||||
// q2.forEach((a,b) -> System.out.println(a + " " + b));
|
||||
|
||||
|
||||
//finde die Länder mit ihrer Städte.
|
||||
Map<Country,List<City>> q6 = test.test
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
country -> country,
|
||||
country -> country.getCities().stream()
|
||||
.collect(Collectors.toCollection(ArrayList::new))
|
||||
));
|
||||
|
||||
//q6.forEach((a,b) -> System.out.println(a + " " + b.toString()));
|
||||
|
||||
|
||||
// Durchschnitt jedes Land
|
||||
Map<Country, Double> q5 = test.test.stream()
|
||||
.collect(Collectors.toMap(
|
||||
country -> country,
|
||||
country -> country.getCities().stream()
|
||||
.collect(Collectors.averagingDouble(e -> e.getPopulation()))));
|
||||
|
||||
//q5.forEach((a,b) -> System.out.println(a + " " + b));
|
||||
//
|
||||
// test.test.stream()
|
||||
// .forEach(t -> {
|
||||
// System.out.println(t.getName());
|
||||
// t.getCities().stream()
|
||||
// .forEach(f -> System.out.println("Stadt: " + f.getName()));
|
||||
// });
|
||||
|
||||
|
||||
// Paralleler Stream mit forEach (Reihenfolge nicht garantiert)
|
||||
System.out.println("Paralleler Stream mit forEach:");
|
||||
ArrayList<Integer> s1 = new ArrayList<>();
|
||||
s1.add(1);
|
||||
s1.add(5);
|
||||
s1.add(4);
|
||||
s1.add(2);
|
||||
s1.parallelStream().sorted().forEach(System.out::println);
|
||||
ArrayList<Integer> s4 = s1.stream().parallel().sorted().collect(Collectors.toCollection(ArrayList::new));
|
||||
System.out.println(s4);
|
||||
|
||||
System.out.println("\nParalleler Stream mit forEachOrdered:");
|
||||
// Paralleler Stream mit forEachOrdered (Reihenfolge garantiert)
|
||||
ArrayList<Integer> s2 = new ArrayList<>();
|
||||
s2.add(1);
|
||||
s2.add(5);
|
||||
s2.add(4);
|
||||
s2.add(2);
|
||||
s2.parallelStream().sorted().forEachOrdered(System.out::print);
|
||||
}
|
||||
|
||||
public static void cityTest() {
|
||||
CityTest test = new CityTest();
|
||||
//Map<Integer, List<City>>
|
||||
City x = test.cities.values()
|
||||
.stream()
|
||||
.max(Comparator.comparingInt(c -> c.getPopulation()))
|
||||
.orElse(null);
|
||||
|
||||
System.out.println(x.toString());
|
||||
|
||||
Map<String, List<City>> nachCod = test.cities.values()
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(t -> t.getCountryCode(), Collectors.toCollection(ArrayList::new)));
|
||||
|
||||
nachCod.forEach((a,b) -> System.out.println("countryCode: " + a + " " + b));
|
||||
|
||||
}
|
||||
|
||||
public static void movieTest() {
|
||||
MovieTest test = new MovieTest();
|
||||
//
|
||||
// Map<Director, Long> moviesPerDirector = test.movies.values().stream()
|
||||
// .flatMap(movie -> movie.getDirectors().stream())
|
||||
// .collect(Collectors.groupingBy(director -> director, Collectors.counting())); // Gruppieren und zählen
|
||||
//
|
||||
//
|
||||
// moviesPerDirector.forEach((director, count) -> {
|
||||
// System.out.println("Director: " + director.getName() + ", Movies: " + count);
|
||||
// });
|
||||
//
|
||||
//
|
||||
// Map<Genre,Long> anzahlGenresjedesFilm = test.movies.values().stream()
|
||||
// .flatMap(movie -> movie.getGenres().stream())
|
||||
// .collect(Collectors.groupingBy(g -> g , Collectors.counting()));
|
||||
//
|
||||
// anzahlGenresjedesFilm.forEach((genre, count) -> {
|
||||
// System.out.println("Genre: " + genre.getName() + ", Movies: " + count);
|
||||
// });
|
||||
|
||||
Map<Boolean, List<Movie>> movies = test.movies
|
||||
.stream()
|
||||
.collect(Collectors.partitioningBy(m -> m.getGenre().equalsIgnoreCase("Drama") || m.getGenre().equalsIgnoreCase("Komödie"), Collectors.toCollection(ArrayList::new)));
|
||||
|
||||
// List<Movie> ohne = movies.get(false);
|
||||
// ohne.forEach(System.out::println);
|
||||
|
||||
// List<Movie> mit = movies.get(true);
|
||||
// mit.forEach(System.out::println);
|
||||
|
||||
Map<Integer, List<Movie>> nachJahr = test.movies
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(m -> m.getYear(), Collectors.toCollection(ArrayList::new)));
|
||||
|
||||
nachJahr.forEach((a,b) -> System.out.println(a +" "+ b + "\n"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue