3:11 pm - Saturday November 23, 2622

Java Example Program for delete element in array

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

public class DeleteArray {
/**
* @Author:candid
* @Description:To Delete a element in an Array
*/

public static void main(String[] arguments) {
// internalize the array
int arg[] = { 5, 6, 8, 9, 10 };
// Delete the Array Element position
int pos = 3;
// Before Delete Array Output
for (int k = 0; k < arg.length; k++) {
System.out.println(arg[k]);
}
for (int i = 0; i < arg.length; i++) {
// Delete Function
if (pos == i) {
for (int j = i + 1; i < arg.length - 1; j++) {
arg[i] = arg[j];
i++;
}
}
}
// After delete the array element Output
System.out.println("The output of Array After Delete");
for (int i = 0; i < arg.length - 1; i++) {
System.out.println(arg[i]);
}
}
}

Output:

5

6

8

9

10

The output of Array After Delete

5

6

8

10

 

Filed in: Sample Programs in java

Comments are closed.