code: public static <T> T[] filter(T array[], Filter<T> filter){
          List<T> filteredList = new ArrayList<T>(array.length);
          for(T element: array){
              if(filter.select(element))
                  filteredList.add(element);
          }
          @SuppressWarnings("unchecked")
          T filteredArray[] = (T[])Array.newInstance(array.getClass().getComponentType(), filteredList.size());
          return filteredList.toArray(filteredArray);
      }
docs: Returns new array which contains only those elements from given {@code array}
  which are selected by the {@code filter}
  
  @param array the array to be filtered
  @param filter filter to use
  
  @return filtered array