When can I use Arrays over Arraylists in Java? And why? - RameshMF/java-interview GitHub Wiki

  • Arrays can be used when you have a fixed number of elements to work on and you’re sure this number is never going to change. Arrays also offer a neat way of storing data in multiple rows and columns (multi-dimensional arrays).

  • But even with that, you can still simultaneously enjoy the strength of an Array and the strength of an ArrayList because Java allows you to convert from an Array to an ArrayList and vice-versa.

  • To convert from an ArrayList to an Array, use the toArray() method. To convert from an Array to an ArrayList, use the Array.asList() method.