1

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!

marrrschine
  • 622
  • 2
  • 10
  • 21

4 Answers4

1

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.

Ulaga
  • 863
  • 1
  • 8
  • 17
1

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.

Azar
  • 1,086
  • 12
  • 27
0

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

A Paul
  • 8,113
  • 3
  • 31
  • 61
0

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

Aroon
  • 167
  • 1
  • 8