Hi, im just doing some past exam papers for an exam I've got coming up and im struggling with Java generics, i cant seem to find any good examples to help me out. I've found small snippets of code but i really need a larger piece of code shown before and after generic implementation so that i can understand properly what is going on. Anyway if no one can provide this i do have a piece of code which wuld be nice if you could implement gerneric code into and explain what you did.
Example code:
public class Queue {
private int[] items = new int[5];
private int top = 0;
public boolean isEmpty() {
return top <= 0;
}
public int get() {
int first = items[0];
for (int i = 0; i+1 < top; i++) {
items[i] = items[i+1];
}
top--;
return items[0];
}
public void add(int i) {
items[top++] = i;
}
public void remove(int i) {
if (i <= 0) return;
get();
remove(i - 1);
}
public static void main(String[] args) {
Queue s = new Queue();
s.add(3);
s.remove(2);
}
}
Thanks,
~Crag