collections.sort一个CustomObject ArrayList,它有多种类型

时间:2015-08-21 18:54:33

标签: java

所以我做了一个CustomObject:

class CustomObject {
        int v1;
        String v2;
        CustomObject(int v1, String v2) {
            this.v1 = v1;
            this.v2 = v2;
        }
    }

然后列出一个清单:

List<CustomObject> myList = new ArrayList<CustomObject>();

然后我使用for

将大量信息添加到此列表中
for(ITS NOT NECESSARY){
                CustomObject o1 = new CustomObject(AN INTEGER HERE,A STRING HERE);
                myList.add(o1);
}

我想通过使用顺序为v1(THE INTEGER ONE)的Collectors.sort来订购它们。就像第一个将是v1具有最大价值的元素一样,依此类推。我不会&#39;我知道怎么样。我看着Javadoc但没找到它 代码应该是这样的

Collections.sort(myList, v1);

1 个答案:

答案 0 :(得分:1)

func addBall(){

        //create ball sprite
        var ball = SKSpriteNode(imageNamed: "ball.png")

        //create physics for ball
        ball.physicsBody = SKPhysicsBody(rectangleOfSize: ball.size) // 1
        ball.physicsBody?.dynamic = true // 2
        ball.physicsBody?.categoryBitMask = PhysicsCategory.Ball // 3
        ball.physicsBody?.contactTestBitMask = PhysicsCategory.Person & PhysicsCategory.Ground
        ball.physicsBody?.collisionBitMask = PhysicsCategory.None // 5

        //generate random postion along x axis for ball to spawn
        let actualX = random(min:ball.frame.size.width/2+1, max: self.frame.size.width - ball.frame.size.width/2-1)
        println(actualX)
        //set balls positon
        ball.position = CGPoint(x: actualX, y: size.height - ball.size.width/2)

        //add ball to scene
        addChild(ball)

        //determine speed of ball
        let actualDuration = random(min: CGFloat(3.0), max: CGFloat(5.0))

        //create movement actions
        let actionMove = SKAction.moveTo(CGPoint(x:actualX, y:  -ball.size.width/2), duration: NSTimeInterval(actualDuration))

        let actionMoveDone = SKAction.removeFromParent()


        ball.runAction(SKAction.sequence([actionMove, actionMoveDone]), withKey: "action")


    }