Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.opencsv.CSVReader;
- import org.apache.commons.lang3.StringUtils;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.HashMap;
- import java.util.Map;
- public class Main {
- public static void main(String[] args) {
- HashMap<String, Integer> map = new HashMap<>();
- int j = 0;
- try {
- for (int i = 0; i < 55; ++i) {
- CSVReader reader = new CSVReader(new FileReader("./plik.csv"), ';');
- String[] nextLine;
- reader.readNext();
- while ((nextLine = reader.readNext()) != null) {
- String[] person = nextLine[i].split("/");
- if (person[0].equals("") || person[0].equals(" ")) {
- break;
- }
- String key = StringUtils.substringBetween(nextLine[i], ".", "/");
- Integer num = map.getOrDefault(key, 0);
- map.put(key, num + Integer.parseInt(person[1]));
- }
- reader.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- System.out.println(map.size());
- map.entrySet().stream()
- .sorted(Map.Entry.comparingByValue())
- .forEach(System.out::println);
- }
- }
Add Comment
Please, Sign In to add comment