how to delete an element from an array in java
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]);
}
}
}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 - 1; i++){
System.out.print(" " + intArr[i]);
}
}
}
Also in Java:
- Title
- socket in java
- Category
- Java
- Title
- java iterate over list
- Category
- Java
- Title
- java read each lines in file
- Category
- Java
- Title
- how to create a Rectangle in java
- Category
- Java
- Title
- protect java
- Category
- Java
- Title
- java execute for cycle parallel thread
- Category
- Java
- Title
- java how to iterate through a arraylist
- Category
- Java
- Title
- java read from file
- Category
- Java
- Title
- eliminar fila jtable java
- Category
- Java
- Title
- java startActivity crash
- Category
- Java
- Title
- how to append to an array in java
- Category
- Java
- Title
- java how to print an array
- Category
- Java
- Title
- charat(0).touppercase() java
- Category
- Java
- Title
- pretty print json in console
- Category
- Java
- Title
- how to make a minecraft hacked client drawing the hud malicious intent
- Category
- Java
- Title
- java read file bufferedreader
- Category
- Java
- Title
- how to create an array of arraylist in java
- Category
- Java
- Title
- javafx textarea size
- Category
- Java
- Title
- jsonobject to java object
- Category
- Java
- Title
- write an object java in a file
- Category
- Java
- Title
- how to find the divisors of a number in java
- Category
- Java
- Title
- string to arraylist convert java
- Category
- Java
- Title
- simple calculator program in java
- Category
- Java
- Title
- processing play sound
- Category
- Java
- Title
- java get annotation value
- Category
- Java
- Title
- java print type of object
- Category
- Java
- Title
- how to use lambda in java
- Category
- Java
- Title
- java get last char of string
- Category
- Java
- Title
- how to create an action listener in java
- Category
- Java
- Title
- counting repeated characters in a string in java
- Category
- Java
- Title
- java hashmap example
- Category
- Java
- Title
- java get environment variables
- Category
- Java
- Title
- generate random number java
- Category
- Java
- Title
- print int in java
- Category
- Java
- Title
- java optional to collection
- Category
- Java
- Title
- date to string java
- Category
- Java
- Title
- how to multiply a number by itself using for loop in java
- Category
- Java
- Title
- gradle require java version
- Category
- Java
- Title
- java create a set with values
- Category
- Java
- Title
- java print treemap
- Category
- Java
- Title
- java output array lists to file
- Category
- Java
- Title
- java how to compare strings
- Category
- Java
- Title
- how to remove all whitespace from string java
- Category
- Java
- Title
- java uuid
- Category
- Java
- Title
- android studio keep device awake
- Category
- Java
- Title
- how to make an array in java
- Category
- Java
- Title
- que es un length en java
- Category
- Java
- Title
- snackbar not showing with bottom nav
- Category
- Java
- Title
- android studio centering textview in relativelayout
- Category
- Java
- Title
- and roid shape setCornerRadii
- Category
- Java
- Title
- how to replace in java
- Category
- Java
- Title
- how lock horizontal orientation android
- Category
- Java
- Title
- number to char java
- Category
- Java
- Title
- initialize scanner java
- Category
- Java
- Title
- isSelfDivisor java
- Category
- Java
- Title
- priority queue java reverse order
- Category
- Java
- Title
- java how to get all threads
- Category
- Java
- Title
- get current day java
- Category
- Java
- Title
- run spring boot application command line
- Category
- Java
- Title
- iterator for array java
- Category
- Java
- Title
- java max
- Category
- Java
- Title
- convert string to array java
- Category
- Java
- Title
- how to create a constructor in java
- Category
- Java
- Title
- java random number in range
- Category
- Java
- Title
- could not initialize defaultkotlinsourcesetkt intelij
- Category
- Java
- Title
- java hashtable
- Category
- Java
- Title
- android get distance between two locations kotlin
- Category
- Java
- Title
- how to check how many anagrams a word has in java
- Category
- Java
- Title
- Category
- Java
- Title
- install java debian 8
- Category
- Java
- Title
- applicationcontext.xml
- Category
- Java
- Title
- java method
- Category
- Java
- Title
- java lambda list of objects cast
- Category
- Java
- Title
- scan a string using scanner class in java
- Category
- Java
- Title
- java initialize float to zero
- Category
- Java
- Title
- java mysql springboot jpa stackoverflow
- Category
- Java
- Title
- inputstream to string java
- Category
- Java
- Title
- java round double to 2 decimal places
- Category
- Java
- Title
- create color object java
- Category
- Java
- Title
- prendere valore da tastiera java
- Category
- Java
- Title
- java type casting
- Category
- Java
- Title
- how to close a jframe in java with an if statement
- Category
- Java
- Title
- spigot action bar
- Category
- Java
- Title
- how to stop screen rotation in android code
- Category
- Java
- Title
- fragment manager in android
- Category
- Java
- Title
- java string length validation regex
- Category
- Java
- Title
- dictionary in java
- Category
- Java
- Title
- java public private key encryption
- Category
- Java
- Title
- loop while in java
- Category
- Java
- Title
- string reverse in java
- Category
- Java
- Title
- java create directory
- Category
- Java
- Title
- python to java converter
- Category
- Java
- Title
- java vector push_back
- Category
- Java
- Title
- abstract class java constructor
- Category
- Java
- Title
- get drawable with string android java
- Category
- Java
- Title
- how to get a user to add to an arraylist in java
- Category
- Java
- Title
- how to play an audio in java
- Category
- Java
- Title
- best companies to workk in
- Category
- Java
- Title
- java recursion
- Category
- Java
- Title
- @fortawesome/free-solid-svg-icons
- Category
- Java