Java (add2)

Add an element to the specified location with the add method to the ArrayList "array" used last time.

ArrayList<String> array = new ArrayList<String>();

array.add ("Japanese"); array.add ("English"); array.add ("French"); array.add ("Chinese"); array.add ("German");

System.out.println(array);

[Japanese, English, French, Chinese, German]

Insert the element "Italian" into index 1.

array.add (1, "Italian"); System.out.println(array);

The output in the list is as follows.

[Japanese, Italian, English, French, Chinese, German]

The element is inserted at the specified location, and the elements after that are shifted to the back. By the way, if you try to insert an element by specifying a location that does not exist An exception called "IndexOutOfBoundsException" occurs.

Recommended Posts

Java (add2)
Java (add)
[Java] Initialize, add, get
Java
Java
java: Add date [Note]
Add multi-letter watermark to Java Word
Java learning (0)
[Java] array
Java protected
[Java] Module
Java array
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Java methods
Java method
Java array
[Java] ArrayDeque
java (method)
Java Day 2018
Java string
java (array)
Java static
Java serialization
java beginner 4
JAVA paid
Studying Java ―― 4
Java (set)
java shellsort
[Java] compareTo
Studying Java -5
java reflexes
java (interface)
☾ Java / Collection
Java array
Studying Java ―― 1
[Java] Array
[Java] Polymorphism
Studying Java # 0
Java review
java framework
Java features
[Java] Inheritance
FastScanner Java
Java features
java beginner 3
Java memo
java (encapsulation)
Java inheritance
[Java] Overload
Add, modify, delete JAVA PDF bookmarks
Java basics
Decompile Java
java notes
java beginner
JAVA (Map)
[java] interface
Java9 collection
Add Bean Validation with Micronaut (Java)
Java basics