Last active
January 7, 2019 00:06
-
-
Save stuart-marks/af9bfdeca1f8d991643f2f3a645c215b to your computer and use it in GitHub Desktop.
Processing Large Files in Java, Variation 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- ReadFileJavaApplicationBufferedReader4.java 2019-01-05 20:40:05.000000000 -0800 | |
+++ ReadFileJavaApplicationBufferedReader5.java 2019-01-05 20:40:11.000000000 -0800 | |
@@ -46,6 +46,8 @@ | |
ArrayList<String> firstNames = new ArrayList<>(); | |
var namePat = Pattern.compile(", \\s*([^, ]+)"); | |
+ char[] chars = new char[6]; | |
+ StringBuilder sb = new StringBuilder(7); | |
System.out.println("Reading file using " + Caller.getName()); | |
@@ -63,11 +65,12 @@ | |
} | |
String rawDate = array1[4].strip(); | |
- String month = rawDate.substring(4,6); | |
- String year = rawDate.substring(0,4); | |
- String formattedDate = month + "-" + year; | |
- dates.add(formattedDate); | |
- | |
+ rawDate.getChars(0, 6, chars, 0); | |
+ sb.setLength(0); | |
+ sb.append(chars, 0, 4) | |
+ .append('-') | |
+ .append(chars, 4, 2); | |
+ dates.add(sb.toString()); | |
} | |
for (int i : indexes) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment