Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Java List/Collections/Map something idk

I'm trying to find out if it's possible with the capabilities of Java, without having to right helper methods but rather do it in a few lines of code.

So what I am looking for is essentially a list with a set amount of entries.

So like

Code
int[] recentVisitors = new int[5];

I essentially want to set the latestVisitor to recentVisitors[0] and move everyone ++ except for the last guy, which he would simply be GC'd.

I UNDERSTAND that I can do this with my array. I was curious if Java has something that does this, I know there's a lot of shit that I don't know about so I am just trying to expand my knowledge.

Thanks in advance,

- Loses
Why not just use a stack or queue for this? I'm a little confused what you're trying to do, but one of these should be better fit for the job than an array.
(Mar 16, 2017 08:44 PM)GenericSkid Wrote:  Why not just use a stack or queue for this? I'm a little confused what you're trying to do, but one of these should be better fit for the job than an array.

(Mar 17, 2017 03:10 AM)Owl Wrote:  I agree with Lord pancake, a stack is well suited.

An alternative is your own wrapper of List and override add(all) to check sizing and placement.

A stack, thanks.
Guava has a version of this called an EvictingQueue.
It sounds like you need a Queue of a fixed size.
[Image: TEGE4Zx.png]

Puzzle level: 2/5


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Ineed2learn2eatJul 13, 2017 10:48 AM 3 230 Jul 13, 2017 10:48 AM
Last Post: Ineed2learn2eat
[Java] by FolksAug 3, 2016 06:48 AM 5 305 Aug 3, 2016 06:48 AM
Last Post: BeNT-
[.NET] by #KatOct 13, 2015 12:30 PM 2 80 Oct 13, 2015 12:30 PM
Last Post: #Kat