Basically, you have a Friend object, which consists of an ID, and a List of Friend objects. Given your friend object, find out if you have any connection to a friend with a particular ID.
public class Friend {
public int id;
public ArrayList<Friend> friendsList;
public boolean checkForConnection(Friend exampleFriend) {
//In this function, check to see if you have any (no matter how distant) connection to the friend object passed in
}
}