Differences between IndexOutOfBoundsException and ArrayIndexOutOfBoundsException

Differences in IndexOutOfBoundsException

IndexOutOfBoundsException

Thrown to indicate that some index (array, string, vector, etc.) is out of range.

Exception that occurs when accessing ** List, ArrayList **, etc. using an invalid index

* Features of ArrayList

Initialization

import java.util.ArrayList; //Package import required
import java.util.List;

ArrayList <Reference type>list name= new ArrayList<>();
List <Reference type>list name= new ArrayList<>(); 
//It is also possible to declare with the List type interface implemented by ArrayList.

--You can handle ** any type of object . ** Mixed type ** is also possible --Automatically increase the number of elements as needed (variable length) ** - Arrange in the order of addition ** -** null ** can also be added as a value -** Duplicate ** is allowed --Not thread safe. An exception (ConcurrentModificationException) occurs when an element is changed during reading.

What is ArrayIndexOutOfBoundsException?

ArrayIndexOutOfBoundsException

A subclass of IndexOutOfBoundsException.

Thrown to indicate that the array was accessed using an invalid index. That is, if the index is negative or greater than or equal to the size of the array.

Exception that occurs when accessing ** array ** using an invalid index

* Characteristics of the array

·Initialization

int a = new int[3]; //Allocate memory as an array with 3 elements

int b [] = {1,2}; //Can be initialized only with an initializer without using new

int[]c = new int []{1,2}; //If you use both new and initializer[]Inside is empty

int[] d;
d = new int[]{2,3};

-** Only the same type ** or compatible types can be handled --It is necessary to ** decide the number of elements to handle first ** --Subscripts must be used for element access --When accessing elements, it is necessary not to exceed the number of elements

point

ArrayList, List are not arrays!

Reference site

[Java] Difference between ArrayIndexOutOfBoundsException and IndexOutOfBoundsException

Recommended Posts

Differences between IndexOutOfBoundsException and ArrayIndexOutOfBoundsException
Differences between "beginner" Java and Kotlin
Differences between Applet class and JApplet class
Differences between Java and .NET Framework
Differences between preface and postfix of operators
[Java] Differences between instance variables and class variables
Differences between Ruby strings and symbols [Beginner]
Differences between Spring Initializr packaging JAR and WAR
[Understanding] Differences between hashes and arrays in Ruby
Summarize the differences between C # and Java writing
Ruby: Differences between class methods and instance methods, class variables and instance variables
Switch between JDK 7 and JDK 8
Difference between vh and%
Difference between i ++ and ++ i
[Ruby] Difference between receiver and object. Differences between Ruby objects and JS objects
Differences between Ruby syntax error statements in Ruby and binary
Differences between browser sessions and cookies and Rails session and cookies methods
Differences between Fetch Type LAZY and EAGER in Hibernate
[Java Bronze learning] Differences between encapsulation, data hiding, and information hiding
Difference between product and variant
Difference between redirect_to and render
Differences between namespace, module, scope and as in Rails routing
[Java] Difference between == and equals
Rails: Difference between resources and resources
Difference between puts and print
Difference between redirect_to and render
Difference between CUI and GUI
[Rails] Differences between redirect_to and render methods and how to output render methods
Difference between variables and instance variables
Relationship between Controller and View
Difference between mockito-core and mockito-all
Difference between class and instance
Difference between bundle and bundle install
Connection between ViewModel and XML
Relationship between package and class
Difference between ArrayList and LinkedList
Difference between render and redirect_to
Think about the differences between functions and methods (in Java)
Difference between List and ArrayList
Differences in how to handle strings between Java and Perl
Difference between .bashrc and .bash_profile
Difference between StringBuilder and StringBuffer
Difference between render and redirect_to
Difference between render and redirect_to
[Ruby] Difference between get and post
Difference between instance method and class method
Difference between interface and abstract class
Difference between == operator and equals method
[Java] Difference between Hashmap and HashTable
Relationship between ActiveRecord with_lock and cache
JavaServlet: Difference between executeQuery and executeUpdate
[Ruby] Difference between is_a? And instance_of?
Difference between == operator and eqals method
Differences between composer install update require
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
Relationship between database and model (basic)
[Java] Relationship between H2DB and JDBC
Difference between Thymeleaf @RestController and @Controller