Question Index

Write a program to add the given element at given index.Use one of the List interface methods.

Input (List, String, int) Output (LinkedList)
[Lion, Tiger, Cat, Rabbit, Mouse], 'Owl', 1 [Lion, Owl, Tiger, Cat, Rabbit, Mouse]
[Suman, Sekhar, Rohan, Sukumar, Praneeth, Prakash], 'Jeevan', 0 [Jeevan, Suman, Sekhar, Rohan, Sukumar, Praneeth, Prakash]
[1, 2, 3, 4, 5, 6], '7', 9 null
[Red, Blue, Green, White, Black, Pink], 'Orchid', -1 null
null null

import java.util.*;
class AddElementAtIndex
    public static void main(String s[])
        LinkedList<String> input = new LinkedList<String>();
        System.out.println("The elements afetr inserted : " + addElementAtGivenIndex(input, "Sql", 5));


    public static LinkedList addElementAtGivenIndex(LinkedList<String> input, String elemet, int index) {




Topic: Java LinkedList

Read this topic
Take test on this topic

Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App