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.