I have an input stream which provides me with a new string every 1 second. I want to store the 25 most recent strings to access at any time. I'm working in Java and do not want to use anything outside of the common library. I would prefer to create a separate class for this implementation.

As an example:

```
String a = "string a";
String b = "string b";
String c = "string c";
...

storedStrings[0] = c;
storedStrings[1] = b;
storedStrings[2] = a;

```

when String d = "string d" arrives I want storedStrings to shift like so:

```
storedStrings[0] = d;
storedStrings[1] = c;
storedStrings[2] = b;
storedStrings[3] = a;

```

and after I've loaded 25 strings in, I no longer care about the value of String a and it should be discarded so as not to take up memory. I've tried ArrayList and am not having success. Is this a use case for Vector?

Point me in the right direction, please!

Updating with my implemented solution, using LinkedList:
--------------------------------------------------------

```
public static void addToQueue(String s){
         if (list == null) list = new LinkedList<>();
           list.addFirst(s);
           System.out.println(s);
           if (list.size() > 25) {
           list.removeLast();
           }
}

```