Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Processing Large Files in Java, Variation 5
--- 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
You can’t perform that action at this time.