LinkedList
Similarly, we define list of Strings as:
LinkedList
Suppose we create a method printArray() to print the above lists. We do it by creating two methods:
printArray(LinkedList
printArray(LinkedList
Generics allows to have a Generic datastructure in the following way:
private
for(E element: argArray){
System.out.println(element);
}
}
E can be a Integer, String or any other Object. The limitation here is the element of type is E is limited to operations pertaining to Object such as wait(), notify(), hashCode() etc.
If we need to define a Type in a class to be used in the class, they can be defined as:
class Printer
D arr;
public
for(T element: array){
System.out.println(element);
}
}
}