标签:i++ index get util str ati pac stat tar
package com.wcc.game.fight;
import java.util.ArrayList;
import java.util.List;
class TestPlayer {
private int index;
private String name;
public TestPlayer() {
}
public TestPlayer(int index, String name) {
this.index = index;
this.name = name;
}
@Override
public String toString() {
return "TestPlayer [index=" + index + ", name=" + name + "]";
}
}
public class MainTest {
public static void printArray(List<TestPlayer> players) {
for (TestPlayer testPlayer : players) {
System.out.println(testPlayer.toString());
}
}
public static void main(String[] args) {
TestPlayer testPlayerA1 = new TestPlayer(1, "A1");
TestPlayer testPlayerA2 = new TestPlayer(2, "A2");
TestPlayer testPlayerA3 = new TestPlayer(3, "A3");
TestPlayer testPlayerA4 = new TestPlayer(4, "A4");
TestPlayer testPlayerA5 = new TestPlayer(5, "A5");
TestPlayer testPlayerA6 = new TestPlayer(6, "A6");
TestPlayer testPlayerB1 = new TestPlayer(1, "B1");
TestPlayer testPlayerB2 = new TestPlayer(2, "B2");
TestPlayer testPlayerB3 = new TestPlayer(3, "B3");
TestPlayer testPlayerB4 = new TestPlayer(4, "B4");
TestPlayer testPlayerB5 = new TestPlayer(5, "B5");
TestPlayer testPlayerB6 = new TestPlayer(6, "B6");
List<TestPlayer> playersA = new ArrayList<TestPlayer>();
// playersA.add(testPlayerA1);
playersA.add(testPlayerA2);
playersA.add(testPlayerA3);
// playersA.add(testPlayerA4);
playersA.add(testPlayerA5);
playersA.add(testPlayerA6);
List<TestPlayer> playersB = new ArrayList<TestPlayer>();
playersB.add(testPlayerB1);
playersB.add(testPlayerB2);
playersB.add(testPlayerB3);
playersB.add(testPlayerB4);
playersB.add(testPlayerB5);
playersB.add(testPlayerB6);
// printArray(playersB);
List<TestPlayer> endPlayers = new ArrayList<TestPlayer>();
// A1 A2 A3 A4 A5 A6
// B1 B2 B3 B4 B5 B6
// 合并两个数组 实现方式 隔位插入就可以实现效果
int maxSideSize = playersA.size() >= playersB.size() ? playersA.size() : playersB.size();
boolean aFirst = true;
for (int i = 0; i < maxSideSize; i++) {
if (aFirst) {
if (i < playersA.size()) {
endPlayers.add(playersA.get(i));
}
if (i < playersB.size()) {
endPlayers.add(playersB.get(i));
}
} else {
if (i < playersB.size()) {
endPlayers.add(playersB.get(i));
}
if (i < playersA.size()) {
endPlayers.add(playersA.get(i));
}
}
}
printArray(endPlayers);
}
}
标签:i++ index get util str ati pac stat tar
原文地址:http://www.cnblogs.com/cci8go/p/7798200.html