Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

arraylist replace value java

list.set(1,"new value");

//example ..

List<String> list = new ArrayList<>();
list.add("one");
list.add("two");
list.add("three");
System.out.println(list); // [one,two,three]
list.set(1,"new");
System.out.println(list); //[one,new,three]
Comment

Change or Replace ArrayList Elements using set() function

import java.util.ArrayList;

class Main {
  public static void main(String[] args) {
    ArrayList<String> animals = new ArrayList<>();

    // add elements in the arraylist
    animals.add("Peacock");
    animals.add("Markhor");
    animals.add("Cow");
    System.out.println("ArrayList: " + animals);

    // change the element of the array list
    animals.set(2, "Dog");
    System.out.println("Modified ArrayList: " + animals);
  }
}
Comment

PREVIOUS NEXT
Code Example
Java :: collapse recycler view on new item click 
Java :: spring environment null pointer exception 
Java :: spring security not going to logout success urk 
Java :: how to disable the auto-configuration? 
Java :: torres de hanoi java 
Java :: java Prefix Sum of Matrix (Or 2D Array) 
Java :: java how to make a 2d eclipse 
Java :: When different programmers write the same program in differing ways and all get the correct result. what is that known as? 
Java :: java vererbung methoden 
Java :: index out of bounds exception java 
Java :: Small Change 
Java :: how to load template file from resource folder in spring boot project 
Java :: java ternärer operator 
Java :: java isalphanum 
Java :: swagger apiimplicitparam all endpoints 
Java :: How authentication manager works in spring security 
Java :: java circular buffer implementation on array 
Java :: Program to check Vowel or Consonant using Switch Case 
Java :: Java TreeMap Example remove() 
Java :: final variables in java 
Java :: java 8 seconds to days 
Java :: how to replace a character with another character in a string in java 
Java :: java indexof not found 
Java :: how to saperate string to array 
Java :: create thread 
Java :: how to create a derived class in Java 
Java :: Mila Kunis 
Java :: exitonclose swing 
Sql :: delete mysql ubuntu 20.04 
Sql :: cant install mysqlclient 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =