Q:

Which practice is better (Calling a method from another method multiple times or do the same thing itself)

I have these two methods in my class. The second method does the same thing but for multiple values in tens of thousands (say fifty thousands). So which one is better to go with:
Edit
public static int isUsed(int num) {
    if((port < startPort || port > endPort)) {
        throw new IllegalArgumentException();
    }
    ServerSocket serverSocket;
    try {
        serverSocket = new ServerSocket(port);
        serverSocket.close();
        return false;
    } catch (IOException e) {
        return true;
    }
}

public static int areAllUsed(int arr[]) {
    //do the same thing several thousand times     >>> Is thisbetters  OR
    // call isUsed several thousand times          >>> this is better
}

With better I mean the memmory or performance.

A:

If you need to reuse a piece of logic in multiple places, defining a function is the best way of reusing the code. Copy-pasting the same logic in another place is not a good idea, because it reduces readability and becomes a maintenance liability in case you must change the logic.
There is little or no performance implications because Java compiler automatically inlines static methods if it finds it beneficial.

