0

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.

ilito
  • 89
  • 7

2 Answers2

2

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));
cegredev
  • 1,485
  • 2
  • 11
  • 25
  • "Just do" but also just read [How do I write a correct micro-benchmark in Java?](https://stackoverflow.com/q/504103/3788176) – Andy Turner Apr 04 '20 at 18:06
1

Definitely an I/O operation would be slower. You need to provide a few more details, for example how often do those codes change? I doubt you mean to add them manually directly into the code.

Ncs
  • 313
  • 1
  • 9