Java String intern: Performance impact | by Ram Lakshmanan | Sep, 2022

public class InternDemo    private static List<String> datas = new ArrayList<>(10_000_000);

public static void main(String args[]) throws Exception

BufferedReader reader = new BufferedReader(new FileReader("C:\workspace\random-data.txt"));
String data = reader.readLine();
while (data != null)
data = reader.readLine().intern();
datas.add(data);

reader.close();

public class NoInternDemo private static List<String> datas = new ArrayList<>(10_000_000);

public static void main(String args[]) throws Exception

BufferedReader reader = new BufferedReader(new FileReader("C:\workspace\random-data.txt"));
String data = reader.readLine();
while (data != null)
data = reader.readLine();
datas.add(data);

reader.close();

Leave a Comment