Menu
Topics Index
...
`

Collections predefined methods


If you need explanation Read this topic

If you need Answer Take test on this topic

Collections predefined methods
What will be the output of the following program?
import java.util.*;
public class RotateElements
{
    public static void main(String[] args)
    {
        List list = Arrays.asList("Pavankalyan Prabhas Nagarjuna Venkatesh Rajanikanth Ram Nitin Krishna Nageshwarrao".split(" "));
        Collections.rotate(list, 5);
        Collections.reverse(list);
        Collections.rotate(list, 3);
        System.out.println("rotate: " + list);
    }
}

A. rotate: [Rajanikanth, Ram, Nitin, Krishna, Nageshwarrao, Pavankalyan, Prabhas, Nagarjuna, Venkatesh]
B. rotate: [Krishna, Nageshwarrao, Pavankalyan, Prabhas, Nagarjuna, Venkatesh, Rajanikanth, Ram, Nitin]
C. rotate: [Nitin, Ram, Rajanikanth, Venkatesh, Nagarjuna, Prabhas, Pavankalyan, Nageshwarrao, Krishna]
D. rotate: [Venkatesh, Nagarjuna, Prabhas, Pavankalyan, Nageshwarrao, Krishna, Nitin, Ram, Rajanikanth]
Topic: java.util.Arrays - Class Arrays In Collection Framework

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

c is answer here we split the values when spacing is occuring and then we rotate the vals at 5 then revers then again rotate op final result is list after 2 rotations and reverse

Posted by Karteek Paruchuri    2013-07-08 09:10:36


ans is C bcoz the strings is sepeerated using spaces and a list is created from it..and rotating the list at 5 th element gives list starting wth rajni as rajni is 5th element from the end.. and now list is reveresed..so rajni bcums last element..and nw list is rotated at 3rd lement from last so gives. ans C as output..on calling rotate wth n as parameter the nth element from the end bcums first element and other elements follows as if in a circle..

Posted by Pramod Jain    2013-07-08 09:17:58


Congratulations Karteek Paruchuri. You are this dose winner. Please send us your mobile details and we will process the recharge asap.

Posted by Merit Campus    2013-07-09 00:54:11


Got the recharge thankyou meritcampus

Posted by Karteek Paruchuri    2013-07-13 13:40:55


© meritcampus 2019

All Rights Reserved.

Open In App