Over a million developers have joined DZone.

Sort Vectors Of Objects In Java

DZone's Guide to

Sort Vectors Of Objects In Java

· ·
Free Resource
Your object must implement the interface Comparable

For example:

public class Link implements Comparable {

	String id_link = "";

	public int compareTo(java.lang.Object o) {
	        //Here you can put your code for compare two objects. Something like this:

	        Link tmp = (Link) o;
	        return this.getId_link().compareTo(tmp.getId_link());

Sorting the Vector:




Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}