Difference between List and ArrayList

List Created like this

List<Integer> list = Arrays.asList(array);

** *: If you use the add method etc., a run-time error will occur ** Since it only refers to array, if you change array, it will be reflected.

ArrayList Created like this

List<Integer> arrayList = new ArrayList<Integer>(Arrays.asList(array));

Postscript (2020/1/28)

As you pointed out and the content was interesting, it is described The reason for throwing an exception when using the ʻadd method of ʻArrayList, which is the return value of ʻArrays.asList (array)`, is as follows.

  1. The ʻArrayList class does not inherit from the ʻadd method and uses the ʻadd` method of the parent class.
  2. The ʻAbstractList inherited by the ʻArrayList class implements ʻadd` to throw an exception (because it is premised on overriding).

Recommended Posts

Difference between List and ArrayList
Difference between ArrayList and LinkedList
[Java] Difference between array and ArrayList
Difference between EMPTY_ELEMENTDATA and DEFAULTCAPACITY_EMPTY_ELEMENTDATA in ArrayList
Difference between vh and%
Difference between i ++ and ++ i
[Java] Understand the difference between List and Set
Difference between product and variant
Difference between redirect_to and render
[Java] Difference between == and equals
Rails: Difference between resources and resources
Difference between puts and print
Difference between redirect_to and render
Difference between variables and instance variables
Difference between mockito-core and mockito-all
Difference between class and instance
Difference between bundle and bundle install
Difference between render and redirect_to
Difference between .bashrc and .bash_profile
Difference between StringBuilder and StringBuffer
Difference between render and redirect_to
Difference between render and redirect_to
Difference between instance method and class method
Difference between render method and redirect_to
Find the difference between List types
Difference between interface and abstract class
Difference between == operator and equals method
[Java] Difference between Hashmap and HashTable
[Terminal] Difference between irb and pry
[Ruby] Difference between is_a? And instance_of?
Difference between == operator and eqals method
Rough difference between RSpec and minitest
[Rails] Difference between find and find_by
Understand the difference between each_with_index and each.with_index
Difference between instance variable and class variable
[JAVA] Difference between abstract and interface
Difference between Thymeleaf @RestController and @Controller
Difference between Stream map and flatMap
Difference between primitive type and reference type
Difference between string.getByte () and Hex.decodeHex (string.toCharaArray ())
[Java] Difference between Closeable and AutoCloseable
[Java] Difference between StringBuffer and StringBuilder
[Java] Difference between length, length () and size ()
[rails] Difference between redirect_to and render
[Android] Difference between finish (); and return;
Difference between element 0, null and empty string (check in list)
Note: Difference between Ruby "p" and "puts"
Difference between final and Immutable in Java
[Memo] Difference between bundle install and update
LinkedList and ArrayList
Difference between Ruby instance variable and local variable
Difference between pop () and peek () in stack
[For beginners] Difference between Java and Kotlin
Difference between isEmpty and isBlank of StringUtils
Difference between getText () and getAttribute () in Selenium
About the difference between irb and pry
Difference between "|| =" and "instance_variable_defined?" In Ruby memoization
Arrylist and linked list difference in java
Difference between addPanel and presentModally of FloatingPanel
[Ruby] Difference between print, puts and p
[Java] Difference between Intstream range and rangeClosed