Menu
Topics Index
...
`

Binary Search Of Characters


If you need explanation Read this topic

If you need Answer Take test on this topic

Binary Search Of Characters
What will be the output of the following program?
import java.util.*;

public class BinarySearch
{
    public static void main(String[] args)
    {
        Vector<String> characters = new Vector<String>();
        characters.add("M");
        characters.add("E");
        characters.add("R");
        characters.add("I");
        characters.add("T");
        Collections.reverse(characters);
        Collections.sort(characters);
        int position = Collections.binarySearch(characters, "I");
        System.out.println("Character found at : " + position);
    }
}

A. Character found at : 4
B. Character found at : 3
C. Character found at : 1
D. Compilation Error
E. Runtime Error
Topic: Java Vector

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 the answer.bcz we reversed the characters added and then searched.

Posted by Shabaaz Shaikz    2014-04-14 13:36:49


Option : C as we  have added the items as M,E,R,I,T then reversed it T,I,R,E,M  and sorted them that makes the list have the items as E,I,M,R,T so position is I is 1 as the count starts from 0

Posted by Deepak Kumar Yadav    2014-04-14 13:59:15


ans is C as Like an array, elements of a Vector object can be accessed via an index into the vector first it adds M,E,R,I,T and reversed the chracters and sorted the chracters in the vector and I is founded at index 1

Posted by Bharath Yelchuri    2014-04-14 15:51:44


Congratulations Deepak Kumar Yadav. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-04-15 03:55:15


© meritcampus 2019

All Rights Reserved.

Open In App