I want to add an Object to a list or a set. Only 5 Objects shall be stored there. If the list is full, and a new Object wants to join (and it will every 50ms), the first (and oldest) element should be deleted. Since I'm addicted to jdk 1.3 (without any extensions!) I didn't find a good solution. Any ideas of an elegant, easy and fast way? Thanks!
-
1What about writing your own class that uses a list internally and enforces said restrictions when adding elements? – reto Dec 17 '13 at 10:29
-
3Why do you use `JDK 1.3` ? – Ruchira Gayan Ranaweera Dec 17 '13 at 10:29
4 Answers
check when you're going to add a element that the list has 5 objects? if so delete the 0th object & add the new object, if it has less than 5 then add it directly. like ABP
said you can do it in jdk 1.3 itself.

- 863
- 1
- 8
- 17
As reto said, you can write your own structure to enforce whatever restrictions you wish on the data. It seems that you want to implement queue-like behavior. You can extend queue, so that you don't have to rewrite much of it's behavior (see http://docs.oracle.com/javase/tutorial/collections/custom-implementations/). However, if this solution is unappealing to you, you can simply implement a class with an internal array-list, and customize the behavior of the add
method.

- 1,086
- 12
- 27
java 1.3 supports collection. You can write your own ArrayList implementation for this. I am not sure what do you mean by "extensions".

- 8,113
- 3
- 31
- 61
You can find here how to optimize the collections in JDK 1.3 or 1.2 http://www.precisejava.com/javaperf/j2se/Collections.htm#Collections102

- 167
- 1
- 8