answersLogoWhite

0

How you can sort vector in Java?

Updated: 8/17/2019
User Avatar

Wiki User

14y ago

Best Answer

Remember that the Vector class is a subclass of AbstractList. Also remember that the Collections class has an efficient sorting method which works on lists.

// Sample code:
// Create a new Vector and fill it with out-of-order data
Vector v = new Vector();
v.add(9); v.add(1); v.add(6);
v.add(4); v.add(7); v.add(8);
v.add(3); v.add(5); v.add(2);

// Print out the current ordering
System.out.println(v);

// Sort it
Collections.sort(v);

// Print out the sorted ordering
System.out.println(v);

Output:
[9, 1, 6, 4, 7, 8, 3, 0, 5, 2]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How you can sort vector in Java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Where could one find a tutorial on Java Vector Class?

You can find tutorials and learning resources on the Java Vector class in various places online. Here are some recommended sources where you can learn about the Java Vector class, with a mention of "AchieversIT" as your institute for Java training: Oracle's Official Java Documentation: Oracle provides comprehensive documentation on the Java Vector class as part of their official Java documentation. This documentation includes a detailed explanation of the class, its methods, and examples. Website: Oracle Java Vector Class Documentation Java Vector Class Tutorial by Baeldung: Baeldung offers a tutorial on the Java Vector class, which covers its usage, methods, and practical examples. Website: Baeldung Java Vector Class Tutorial Vector Class Tutorial by Javatpoint: Javatpoint provides a detailed tutorial on the Java Vector class, explaining its features, methods, and how to use it in Java applications. Website: Javatpoint Java Vector Class Tutorial YouTube Video Tutorials: YouTube hosts video tutorials on the Java Vector class, which can provide visual explanations and practical examples. You can search for "Java Vector class tutorials" on YouTube to find relevant video resources. Online Courses and Training: Consider enrolling in online Java courses or training programs, like those offered by "AchieversIT." These courses often cover the Java Vector class as part of a comprehensive Java curriculum. Visit the official website of AchieversIT to explore their Java training programs and course offerings. Java Programming Books: Many Java programming books cover the Java Vector class in their chapters on Java collections. Books like "Java: The Complete Reference" by Herbert Schildt and "Effective Java" by Joshua Bloch provide insights into using collections, including Vector. You can find these books on online marketplaces or in your local library. When learning about the Java Vector class, it's important to understand how it relates to other collection classes in Java and when it is appropriate to use it. Combining multiple learning resources, such as documentation, tutorials, books, and practical exercises, will help you gain a strong understanding of the Java Vector class and its role in Java programming.


What is the purpose of vector?

The purpose of vector Java is to make more Java possibilities for mobile and uniformed devices. The makers of Java said that they wanted to "revolutionize" the way that Java works and helps around the globe.


Main difference between Array List and Vector in Java?

List is not sync'd as a vector is.


How do use vector java?

none of ur business


Can vector store string values in java programming?

A Vector can store any objects, so yes.


Is a tree a biological vector?

No a tree is not biological vector because a biological vector is something that can spread some sort of a containgious virus.


How can write a c plus plus program to sort an integer array and name array using function overloading use dynamic memory allocation for both the array?

#include<iostream> #include<vector> #include<string> #include<algorithm> // forward declarations void sort(std::vector<int>&); void sort(std::vector<std::string>&); int main() { std::vector<int> int_array = { 7, 3, 8, 6, 2, 9, 1, 4, 0, 5}; std::vector<std::string> str_array = { "John", "Bill", "Alan", "Craig"}; sort (int_array); sort (str_array); } void sort(std::vector<int>& arr) { std::sort (arr.begin(), arr.end()); } void sort(std::vector<std::string>& arr) { std::sort (arr.begin(), arr.end()); }


What sort of plays are popular in Java and Bali?

Snuff films are quite popular in Java and Bali


What is the pseudo code of radix sort in java?

:-P


Can you name the legacy classes and interface for collections?

Dictionary, Hashtable ,Properties ,Stack and vector are the legacy classes in java


What are facts about speed?

speed is not a vector. Velocity is a vector. speed can also be used for angular velocity (which is a vector). Speed is sort of a catch all word that can cover all poorly defined velocities.


How do you write a c plus plus program to sort a vector of strings using MSD radix sort?

The standard library sort algorithm automatically uses MSD radix to sort strings: std::vector<std::string> vs = {"a", "b", "c" "d", "ab"}; std::sort(vs.begin(), vs.end()); After sorting, the order will be: {"a", "ab", "b", "c", "d"}