Menu
Question Index
...

Write a program to move after the given item to specified item in a list.

Input (String to be moved, Specified String , String List) Output List(After Move)
Sehwag
Dhoni
[Sachin Tendulkar, Sehwag, Yuvraj Singh, Dhoni, Gautam Gambhir, Suresh Raina, Rohit Sharma, Virat Kohli]
[Sachin Tendulkar, Yuvraj Singh, Gautam Gambhir, Dhoni, Sehwag, Suresh Raina, Rohit Sharma, Virat Kohli]
Virat Kohli
Sehwag
[Sachin Tendulkar, Sehwag, Yuvraj Singh, Dhoni, Gautam Gambhir, Suresh Raina, Rohit Sharma, Virat Kohli]
[Sachin Tendulkar, Sehwag, Virat Kohli, Yuvraj Singh, Dhoni, Gautam Gambhir, Suresh Raina, Rohit Sharma]
ECE
MEC
[MEC, EEE, CIVIL, ECE, CSE, IT]
[MEC, ECE, EEE, CIVIL, CSE, IT]
CSE
""{EMPTY}
[MEC, EEE, CIVIL, ECE, CSE, IT]
[MEC, EEE, CIVIL, ECE, CSE, IT]
""{EMPTY STRING}
ECE
[MEC, EEE, CIVIL, ECE, CSE, IT]
[MEC, EEE, CIVIL, ECE, CSE, IT]
CSE
ECE
[]{EMPTY LIST}
[]
CSE
null{NULL STRING}
[MEC, EEE, CIVIL, ECE, CSE, IT]
[MEC, EEE, CIVIL, ECE, CSE, IT]
null{NULL STRING}
null{NULL STRING}
[MEC, EEE, CIVIL, ECE, CSE, IT]
[MEC, EEE, CIVIL, ECE, CSE, IT]
null{NULL STRING}
null{NULL STRING}
null{NULL LIST}
null


import java.util.*;
class MoveAfterGivenItemToSpecifiedItem
{
    public static void main(String s[])
    {
        ArrayList<String> list = new ArrayList<String>();
        list.add("Sachin Tendulkar");
        list.add("Sehwag");
        list.add("Yuvraj Singh");
        list.add("Dhoni");
        list.add("Gautam Gambhir");
        list.add("Suresh Raina");
        list.add("Rohit Sharma");
        list.add("Virat Kohli");
        String itemToBeMoved = "Virat Kohli";
        String specifiedItem = "Sehwag";
        moveAfter(itemToBeMoved, specifiedItem, list);
        System.out.println("The elements are move after the "+itemToBeMoved+" to "+specifiedItem+" in list "+list);

    }


        public static void moveAfter(String itemToBeMoved, String specifiedItem, List<String> list)
        {
        }

}

Doubts

Problems

Topic: Java ArrayList

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App