SkillWeek6 32536
SkillWeek6 32536
while (!maxHeap.isEmpty()) {
Map.Entry<Character, Integer> current = maxHeap.poll();
result.append(current.getKey());
current.setValue(current.getValue() - 1);
prev = current;
}
if (result.length() != s.length()) {
return "";
}
return result.toString();
}
String s1 = "aab";
String s2 = "aaab";
System.out.println(z.reorganizeString(s1));
System.out.println(z.reorganizeString(s2));
}
}
2) Advanced Type Bounds with Generics
Objective: Create a generic class that uses advanced type bounds and wildcards and
understand how the generic methods work with type bounds and wildcards. Details:
Class Definition: a) Define T with multiple bounds: it must implement both Comparable.
Methods: a) processList(List list): This method should process a list of elements that are
of type T or its subtypes. It should iterate through the list and print each element. b)
addToList(List list, T element): This method should add an element of type T to a list that
can hold T or any supertype of T. Use Case: a) Create a Product class that implements
Comparable and Serializable. b) Use AdvancedGeneric with Product to: Process a list of
Product objects. Add a new Product to another list and process it.
Code:
package SkillWeek6;
import java.io.Serializable;
import java.util.*;
class Product implements Comparable<Product>, Serializable {
private String name;
private double price;
Code:
package SkillWeek6;
import java.util.*;
class Employee implements Comparable<Employee> {
private String name;
private Integer age;
private Double salary;
return this.salary.compareTo(other.salary);
}
return e1.getName().compareTo(e2.getName());
}
}