Agent collision avoidance java
A very efficient approach to what you are trying to do is velocity obstacles.

Assuming two agents use constant velocity motion vectors, a velocity obstacle models a geometric region in which if the endpoint of the velocity vector for agent 1 falls, it will collide with agent 2 (and vice versa). Hence you can predict what velocity vectors will lead to collisions between the agents and choose velocity vectors that do not collide.

There are very good examples and tutorials here:
http://gamma.cs.unc.edu/RVO/