deleting elements of an array in java
import java.util.Scanner;
public class ElemRemoval {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] intArr = {1, 2, 5, 12, 7, 3, 8};
System.out.print("Enter Element to be deleted : ");
int elem = in.nextInt();
for(int i = 0; i < intArr.length; i++){
if(intArr[i] == elem){
// shifting elements
for(int j = i; j < intArr.length - 1; j++){
intArr[j] = intArr[j+1];
}
break;
}
}
System.out.println("Elements -- " );
for(int i = 0; i < intArr.length; i++){
System.out.print(" " + intArr[i]);
}
}
}
Also in Java:
- how to crate a list in java script
- dataframe to dict without index
- how to remove a certain string in a arraylist java
- android how to know when snackbar is done
- how to find length of array in java
- java 11 initialize map
- java - get open ports
- how to create a draw Rectangle in java
- dicom read with java
- length of string java
- java random number generator in range
- fxmlloader getresource from another package
- java insert into arraylist
- padding a string with 0 in java
- java windowbuilder full screen
- android java convert double to 2 decimal places
- java observable to observer stack overflow
- creating array java
- how to set a windows background image tkinter
- get current unix timestamp java
- java 8 findany on null list
- how to do for each in java
- HOW TO SUPRESS sonar warning in java code
- make a commet in java