Advertisement
amitsen01ei

CsvParseMithunJavaVersion.java

Feb 17th, 2024
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | Source Code | 0 0
  1. import java.io.*;
  2. import java.time.*;
  3. import java.util.*;
  4.  
  5. public class CsvParseMithun {
  6.  
  7.     public static void main(String[] args) {
  8.         var startTime = Instant.now();
  9.  
  10.         String filePath = "/Users/amitsen01ei/Downloads/uuids-medium.csv";
  11.         var frequencyMap = new HashMap<Character, Integer>();
  12.  
  13.         try (var reader = new BufferedReader(new FileReader(filePath))) {
  14.             String line;
  15.             while ((line = reader.readLine()) != null) {
  16.  
  17.                 String[] fields = line.split(",");
  18.  
  19.                 for (var field : fields) {
  20.                     for (var ch : field.toCharArray()) {
  21.                         frequencyMap.merge(ch, 1, Integer::sum);
  22.                     }
  23.                 }
  24.             }
  25.         } catch (IOException e) {
  26.             System.err.println(e.getMessage());
  27.         }
  28.  
  29.         frequencyMap.forEach((key, value) -> System.out.println(STR."\{key} = \{value}"));
  30.  
  31.         long executionTime = Duration.between(startTime, Instant.now()).getSeconds();
  32.         System.out.println(STR."Execution Time: \{executionTime} s");
  33.     }
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement