在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