code: @SuppressWarnings("unchecked")
      public static int median(List<Integer> values) {
          if (values == null || values.isEmpty()) return 0;
  
          values = new ArrayList<Integer>(values);
          Collections.sort(values);
  
          final int size = values.size();
          final int sizeHalf = size / 2;
          if (size % 2 == 1) { //is odd?
              // 0 1 [2] 3 4: size/2 = 5/2 = 2.5 -> 2
              return values.get(sizeHalf);
          }
  
          // 0 1 [2 3] 4 5: size/2 = 6/2 = 3
          return (values.get(sizeHalf - 1) + values.get(sizeHalf)) / 2;
      }
docs: Computes the median value of a list of integers.
  @param values    list of values
  @return the computed medium