Menu
Topics Index
...
`

Creating LinkedList


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating LinkedList
What will be the output of the following program?
import java.util.Collections;
import java.util.LinkedList;
public class CanYouDo {
    public static void main(String args[]) {
        LinkedList<String> list = new LinkedList<String>();
        list.add("BbB1");
        list.add("bBb2");
        list.add("bbB3");
        list.add("BBb4");
        Collections.sort(list);
        for (String str : list) {
            System.out.print(str + ":");
        }
    }
}

A. BbB1:bBb2:bbB3:BBb4:
B. BBb4:bbB3:bBb2:BbB1:
C. BBb4:BbB1:bBb2:bbB3:
D. bbB3:bBb2:BbB1:BBb4:
E. Some other output
F. Compilation Error or Runtime Error
Topic: Java Collection Algorithms

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.

ans is C: as ascii vals of B is < b so sorted list will print in that oreder

Posted by Krishna Murthy    2013-07-16 08:35:00


ans should be C as strings are compared according ascii values and b has gerater asci than B

Posted by Pramod Jain    2013-07-16 08:35:34


correct answer is D because after inserting string objects into the Linked list we are calling the sort method of collections class which by default arrange them ascending order based on alphabets

Posted by Ram Reddy Bitla    2013-07-16 08:57:53


C should be the answer as the ASCII values of smaller alphabets are greater than the value of bigger one.

Posted by Jandhyala Sree Vatsava    2013-07-16 10:13:41


c

Posted by Manasa Sudini    2013-07-16 14:39:15


according to ascii values

Posted by Manasa Sudini    2013-07-16 14:39:55


Congratulations Krishna Murthy, you are this dose winner. Please send us your mobile details and we will process the recharge asap.

Posted by Merit Campus    2013-07-18 11:16:37


thanku mc received rc :)

Posted by Krishna Murthy    2013-07-22 15:26:04


© meritcampus 2019

All Rights Reserved.

Open In App