YouTip LogoYouTip

Data Vecsort

# Java Example - Get Index Value of Vector Elements [![Image 3: Java Example](#) Java Example](#) The following example demonstrates using the sort() method of the Collections class to sort a vector and using the binarySearch() method to get the index value of a vector element: ## Main.java File import java.util.Collections; import java.util.Vector; public class Main{public static void main(String[]args){Vector v = new Vector(); v.add("X"); v.add("M"); v.add("D"); v.add("A"); v.add("O"); Collections.sort(v); System.out.println(v); int index = Collections.binarySearch(v, "D"); System.out.println("Element index value is: " + index); }} The output of the above code is: [A, D, M, O, X]Element index value is: 1 [![Image 4: Java Example](#) Java Example](#)
← Data ReplaceThread Stop β†’