Mã:
//class Test <X extends Number, Y, Z extends Double> {
class Test {
static <T extends List, U> T removeObject(T list, U u) {
Iterator<Iterator> it = list.iterator();
while (it.hasNext()) {
if (it.next() == u) {
it.remove();
}
}
return list;
}
}
public class Solution {
public static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) throws Exception {
ArrayList list = new ArrayList<>();
list.add("Hard");
list.add(null);
list.add(2344);
list.add(0.35f);
list.add(null);
list.add('a');
list.add(0.89d);
list.add(null);
list.add(13L);
list.add(true);
System.out.println("Input:");
System.out.println(list);
Test.removeObject(list, null);
System.out.println("\nOutput:");
System.out.println(list);
}
}
Input:
[Hard, null, 2344, 0.35, null, a, 0.89, null, 13, true]
Output:
[Hard, 2344, 0.35, a, 0.89, 13, true]