在Java对象的名单上有这个类:排序根据布尔
public class Turn {
public boolean turnMoved;
public int moveSelectionX;
public int moveSelectionY;
public int moveTargetX;
public int moveTargetY;
public boolean turnFired;
public int shotSelectionX;
public int shotSelectionY;
public int shotTargetX;
public int shotTargetY;
//Set this to true when doing a turn if we fired before moving
//Else if we do move/shot in the wrong order, we might select an empty cell
boolean firedFirst = false;
}
别处在我的计划,我创建这些对象的列表。一旦列表完成后,我想排序顺序列表,让所有满足1对象将在列表的前面,等:
- turnMoved & & turnFired ==真
- turnFired ==真
- turnMoved ==真
- turnMoved & & turnFired ==假
竟被什么d最简单的方法是做什么?
你有什么试过? Web上必须有成千上万个示例,演示如何对Java中的对象列表进行排序。 – 2013-04-05 15:37:43
可能重复的[如何排序集合?](http://stackoverflow.com/questions/2477261/how-to-sort-a-collectiont) –
2013-04-05 15:37:59
你看了一下Comparable接口吗? http://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html – 2013-04-05 15:38:23