Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to replace an element in array in java

class array{
  public static void main(String[] args){
    int arr[] = {1,2,3,4};
    System.out.println("Before update" + arr[2]);
    arr[2] = 9;//updating the value
    System.out.println("After update" + arr[2]);
  }
}

/*output:-
Before update3
After update9*/
Comment

Change element in array Java

String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
System.out.println(cars[0]);

// Change elements in array
cars[0] = "Opel";
System.out.println(cars[0]);

// Length of array
System.out.println(cars.length);

// Loop through array
for (int i = 0; i < cars.length; i++) {
  System.out.println(cars[i]);
}
Comment

PREVIOUS NEXT
Code Example
Java :: priority queue java 
Java :: mergesort java 
Java :: down casting java 
Java :: java 14 switch 
Java :: java parameterized constructor 
Java :: Java Access Array Elements 
Java :: java finally block 
Java :: Java How to use Deque? 
Java :: broadcast receiver for no interner android studio 
Java :: java code for logarithm 
Java :: get string size on screen 
Java :: how to get length of 2d array java 
Java :: how to use java 
Java :: what is method in java 
Java :: find minimum element in a sorted and rotated array 
Java :: java add values to array 
Java :: java inheritance example 
Java :: java application 
Java :: types of exception in java 
Java :: string comparison using == in java 
Java :: run java class file 
Java :: BufferedReader x = new BufferedReader(new InputStreamReader(System.in)); 
Java :: No enclosing instance of type Main is accessible. Must qualify the allocation with an enclosing instance of type Main (e.g. x.new A() where x is an instance of Main). 
Java :: jbutton actionperformed 
Java :: how to extract word from string in java 
Java :: android java string animations 
Java :: arraylist to java 
Java :: arraycopy merging arrays 
Java :: how to add a singleton hashset in java 
Java :: using for each loop for searching in array 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =