Java - TreeMap with Comparator
- OK example
- another example
- RepastEdge<T>
class EdgeCompare implements Comparator
{
public int compare(Object a, Object b)
{
double weightA = (RepastEdge)a.getWeight();
double weightB = (RepastEdge)b.getWeight();
int returnVal;
if (weightA < weightB)
{
returnVal = 1;
}
else if (weightA == weightB)
{
returnVal = 0;
}
else
{
returnVal = -1;
}
return returnVal;
}
}
TreeSet ts = new TreeSet(new EdgeCompare);
How to use Comparator and Comparable in Java? With example
http://javarevisited.blogspot.com/2011/06/comparator-and-comparable-in-java.html#ixzz1uV1pTbSG
http://javarevisited.blogspot.com/2011/06/comparator-and-comparable-in-java.html#ixzz1uV1pTbSG
- negative returned if a < b
- zero if a == b
- positive if a > b
List of Java Exceptions
Java - Arrays
Java - List Example
- interface definition
Java - Class WattsBetaSmallWorldGenerator
Java - Class RepastEdge<T>
Java - for each loop Example
- for (String city : cities)
No comments:
Post a Comment