I'm quite new to this, so sorry if this is a trite question. I have an ArrayList where Node is a custom class. This is how I have defined it:
static class Node implements Comparable<Node> {
String nodeName;
String[] borderingNodes;
public Node(String nodeName, String[] borderingNodes) {
this.nodeName = nodeName;
this.borderingNodes = borderingNodes;
}
public int compareTo(Node node) {
if(borderingNodes.length > node.borderingNodes.length) {
return 1;
}
if(borderingNodes.length == node.borderingNodes.length) {
return 0;
}
if(borderingNodes.length < node.borderingNodes.length) {
return -1;
}
}
}
Now, I tried doing an Arrays.sort(inputNodes)
where inputNodes is an ArrayList... However I got the error:
no suitable method found for sort(ArrayList<Node>)
Arrays.sort(inputNodes);
How do I correctly do this? My sort btw... has to sort on the size of the borderingNodes array.