I have a list of Custom object and i want to find an object by given an Id(a field in custom object). i was coding for this so i found two solutions when comparing fields.
1
private Product getProduct(String productId,List<Product> productList){
        for (int i = 0; i < productList.size(); i++) {
            if (productId.equals(productList.get(i).getId())) {
                return productList.get(i);
            }
        }
        return null;
    }
2.
 private Product getProduct(String productId,List<Product> productList){
        for (int i = 0; i < productList.size(); i++) {
            if (productList.get(i).getId().equals(productId)) {
                return productList.get(i);
            }
        }
        return null;
    }
The difference is in if condition , i want to know which one is better than the other and why, when to use 1st method and when to use second  ?
 
     
     
     
     
    