santaxl

Untitled

Oct 25th, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. import com.opencsv.CSVReader;
  2. import org.apache.commons.lang3.StringUtils;
  3.  
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6. import java.util.HashMap;
  7. import java.util.Map;
  8.  
  9. public class Main {
  10.  
  11. public static void main(String[] args) {
  12. HashMap<String, Integer> map = new HashMap<>();
  13. int j = 0;
  14. try {
  15. for (int i = 0; i < 55; ++i) {
  16. CSVReader reader = new CSVReader(new FileReader("./plik.csv"), ';');
  17. String[] nextLine;
  18. reader.readNext();
  19.  
  20. while ((nextLine = reader.readNext()) != null) {
  21. String[] person = nextLine[i].split("/");
  22. if (person[0].equals("") || person[0].equals(" ")) {
  23. break;
  24. }
  25. String key = StringUtils.substringBetween(nextLine[i], ".", "/");
  26. Integer num = map.getOrDefault(key, 0);
  27. map.put(key, num + Integer.parseInt(person[1]));
  28. }
  29.  
  30. reader.close();
  31. }
  32. } catch (IOException e) {
  33. e.printStackTrace();
  34. }
  35. System.out.println(map.size());
  36. map.entrySet().stream()
  37. .sorted(Map.Entry.comparingByValue())
  38. .forEach(System.out::println);
  39. }
  40. }
Add Comment
Please, Sign In to add comment