import java.util.Vector;
import java.util.Collections;
import static java.lang.System.out;
class SearchList
{
public static void main(String...alt)
{
Vector v=new Vector();
v.add("ravi");
v.add("altaf");
v.add("kanta");
v.add("zahid");
v.add("nani");
out.println("Before Sorting : "+v);
Collections.sort(v);
out.println("After Sorting : "+v);
int result1=Collections.binarySearch(v,"nani");
int result2=Collections.binarySearch(v,"NANI");
out.println("nani is available in index : "+result1);
out.println("NANI is not available in Vector So it insertion point is : "+result2);
//NANI is less than nani(ASCII value of upper case letter is less than ASCII value of lower case letter)
}
}
import java.util.Collections;
import static java.lang.System.out;
class SearchList
{
public static void main(String...alt)
{
Vector v=new Vector();
v.add("ravi");
v.add("altaf");
v.add("kanta");
v.add("zahid");
v.add("nani");
out.println("Before Sorting : "+v);
Collections.sort(v);
out.println("After Sorting : "+v);
int result1=Collections.binarySearch(v,"nani");
int result2=Collections.binarySearch(v,"NANI");
out.println("nani is available in index : "+result1);
out.println("NANI is not available in Vector So it insertion point is : "+result2);
//NANI is less than nani(ASCII value of upper case letter is less than ASCII value of lower case letter)
}
}
0 Comment to "Java Program to search an element in List(Vector)."
Post a Comment