I have found another solution on Google by chance, and I decided to help others who are also looking for collision responses by linking directly and save time Googling for one.
The link is here.
The alternate solution (Author: eBusiness):
public void handleCollisions(){
double xDist, yDist;
for(int i = 0; i < balls.size(); i++){
Ball A = balls.get(i);
for(int j = i+1; j < balls.size(); j++){
Ball B = balls.get(j);
xDist = A.getCenterX() - B.getCenterX();
yDist = A.getCenterY() - B.getCenterY();
double distSquared = xDist*xDist + yDist*yDist;
//Check the squared distances instead of the the distances, same result, but avoids a square root.
if(distSquared <= (A.radius + B.radius)*(A.radius + B.radius)){
double xVelocity = B.xVel - A.xVel;
double yVelocity = B.yVel - A.yVel;
double dotProduct = xDist*xVelocity + yDist*yVelocity;
//Neat vector maths, used for checking if the objects moves towards one another.
if(dotProduct > 0){
double collisionScale = dotProduct / distSquared;
double xCollision = xDist * collisionScale;
double yCollision = yDist * collisionScale;
//The Collision vector is the speed difference projected on the Dist vector,
//thus it is the component of the speed difference needed for the collision.
double combinedMass = A.mass + B.mass;
double collisionWeightA = 2 * B.mass / combinedMass;
double collisionWeightB = 2 * A.mass / combinedMass;
A.xVel += collisionWeightA * xCollision;
A.yVel += collisionWeightA * yCollision;
B.xVel -= collisionWeightB * xCollision;
B.yVel -= collisionWeightB * yCollision;
}
}
}
}
}