Java (set)

【set】 This method is used when rewriting the elements of ArrayList. Enter the location and value you want to change as shown below. Variable name.set (index, value to be rewritten)

In the ArrayList "array" used in Java (add) times Rewrite the element at the location specified by the set method.

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]

Change "Chinese" in Index 3 to "Korean".

array.set (3, "Korean"); System.out.println(array);

The output in the list is as follows.

[Japanese, English, French, Korean, German]

The value at the specified location is rewritten.

Like the add method, if you try to rewrite the value by specifying a location that does not exist An exception called "IndexOutOfBoundsException" occurs.

Recommended Posts

Java (set)
Java
Java
How to set Java constants
Studying Java ―― 3
[Java] array
Java protected
[Java] Annotation
[Java] Module
Java array
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Java methods
Java method
java (constructor)
Java array
[Java] ArrayDeque
java (override)
java (method)
Java Day 2018
Java string
java (array)
Java static
Java serialization
java beginner 4
JAVA paid
Studying Java ―― 4
java shellsort
[Java] compareTo
Studying Java -5
java reflexes
java (interface)
Java memorandum
☾ 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] Collection-List / Set / Map / Stack / Queue
Java features
java beginner 3
Java memo
java (encapsulation)
Java inheritance
[Java] Overload
Java basics
Decompile Java
[Java] Annotation
java notes
java beginner
Java (add2)
JAVA (Map)
[java] interface
Java9 collection