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 :: java compute sum and average of array elements 
Java :: print symbol in pyramid shape in java 
Java :: read qr code from image java 
Java :: set matrix zeros programming creek 
Java :: declare generic set java 
Java :: convert date to localdate java 
Java :: java use variables inside strings 
Java :: list of arrays java 
Java :: add int to list java 
Java :: converting string to int in java 
Java :: write message in file java 
Java :: do while jaca 
Java :: this keyword java 
Java :: java create arraylist with size 
Java :: how to change toolbar name in android studio 
Java :: input using stringbuffer 
Java :: creating an array list in java 
Java :: java continue keyword 
Java :: change text size java 
Java :: lcm of two large positive integers java 
Java :: java sort arraylist of floats 
Java :: how to delete an element from an array in java data structure 
Java :: spring boot put invalid cors request 
Java :: springbootservletinitializer maven dependency 
Java :: variables in java 
Java :: java determine number of cpu cores 
Java :: no java virtual machine found after searching the following locations 
Java :: how to recognize a pressed key in java 
Java :: math.sin in java 
Java :: transparent border of jtextfield in java 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =