Java Program to Insert Element at Specific Position in Array

In this tutorial you will learn about the Java Program to Insert Element at Specific Position in Array and its application with practical example.

Java Program to Insert Element at Specific Position in Array

In this tutorial, we will learn to create a Java program that will insert an Element at a Specific Position in an Array using Java programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following Java programming topics:

  • Operators in Java Programming.
  • Basic Input and Output function in Java Programming.
  • Basic Java programming.
  • For loop in Java programming.
  • Arithmetic operations in Java Programming.

Algorithm:-

Program description:-

In this program, We will first take the size and the elements of the array. Then We will take the new element and its position from the user. At last, we will add the element in the array and will print that to the user.

With the help of this program, we can insert an Element at a Specific Position in the Array.

Program Code:-

Output:-

In the above program, we have first initialized the required variable.

  • positionn = it will hold the integer value for the position.
  • n = it will hold the integer value.
  • i = it will hold the integer value.

Input size and the elements of the array from the user.

Taking the new element and its position from the user to add in the array.

Printing array after adding the element in the array.

In this tutorial we have learn about the Java Program to Insert Element at Specific Position in Array and its application with practical example. I hope you will like this tutorial.