private static int findClosestSize(List<Size> sortedSizes,int targetPixelCount){
  int closestMatchIndex=0;
  int closestMatchPixelCountDiff=Integer.MAX_VALUE;
  for (int i=0; i < sortedSizes.size(); ++i) {
    Size size=sortedSizes.get(i);
    int pixelCountDiff=Math.abs((size.width() * size.height()) - targetPixelCount);
    if (pixelCountDiff < closestMatchPixelCountDiff) {
      closestMatchIndex=i;
      closestMatchPixelCountDiff=pixelCountDiff;
    }
  }
  return closestMatchIndex;
}

private static int findClosestSize ( List < Size > sortedSizes , int targetPixelCount ) { int closestMatchIndex = 0 ; int closestMatchPixelCountDiff = Integer . MAX_VALUE ; for ( int i = 0 ; i < sortedSizes . size ( ) ; ++ i ) { Size size = sortedSizes . get ( i ) ; int pixelCountDiff = Math . abs ( ( size . width ( ) * size . height ( ) ) - targetPixelCount ) ; if ( pixelCountDiff < closestMatchPixelCountDiff ) { closestMatchIndex = i ; closestMatchPixelCountDiff = pixelCountDiff ; } } return closestMatchIndex ; }
returns the index of the size within the given list that is closest to the given target pixel count .
