Is faster to read text file or add elements to ArrayList?

ilito :

I currently add elements to ArrayList using submethod and then call it in the main function:

public void addProductAll(){
        productCode.add("202LED");
        productCode.add("202WLED");
        productCode.add("WWR"); 
        productCode.add("CUBLED"); 

The problem is that I will have 200 different product codes. So my question is what is the fastest way to add elements to the ArrayList? Like I am doing now or maybe read them from text document? Is there a better approach to this problem?

Thank you in advance.

Schred :

You can test this yourself. Just do:

long start = System.nanoTime();
// Add manually
System.out.println("Time taken: " + (System.nanoTime() - start));

and

long start = System.nanoTime();
// Read from file
System.out.println("Time taken: " + (System.nanoTime() - start));

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=409804&siteId=1