napisalem funkcje ktora ma mi tworzyc mape z danych. Wszystko dziala tylko dane na wyjsciu sa inaczej posortowane niz w kolejnosci wprowadzania jak to zmienic?
public HashMap<String,ArrayList<String>> getLangsMap(){
HashMap<String,ArrayList<String>> result = new HashMap<>();
String rows[] = data.split("\n");
for(int i=0; i<rows.length; i++){
ArrayList<String> prog = new ArrayList<>();
String row[] = rows[i].split("\t");
for(int j=1; j<row.length; j++){
prog.add(row[j]);
}
prog = (ArrayList<String>) prog.stream().distinct().collect(Collectors.toList());
System.out.println(row[0]+prog);
result.put(row[0], prog);
}
System.out.println();
return result;
}
Data to taki o to String pobrany z pliku:
Aps Z Y X D
Dossd V S C D A Z
Kas G J T
COAL P S Q V D
Scad A D
A po wyswietleniu tej mapy mamy:
getLangsMap().forEach((k,v)->System.out.println(k+ " = " + v)); //Sposob wyswietlenia ma byc nie zmieniony
Scad = [A, D]
Aps = [Z, Y, X, D]
COAL = [P, S, Q, V, D]
Dossd = [V, S, C, D, A, Z]
Kas = [G, J, T]
Jak nie zmieniac kolejnosci