What is a fast way to remove oldest item in array and ad new one
in
Programming Questions
•
2 years ago
I have a String array
String[] previousWords = new String[maxNearWords];
Every time i look at a word i add it, and i have to remove the oldest one
now i use:
previousWords = splice(previousWords, s, 0);
previousWords = shorten(previousWords);
Wich works, but there are also other method to do it.
Like reverse the array, then shorten it, then revers again and then append.
What is a good way in terms of speed?
String[] previousWords = new String[maxNearWords];
Every time i look at a word i add it, and i have to remove the oldest one
now i use:
previousWords = splice(previousWords, s, 0);
previousWords = shorten(previousWords);
Wich works, but there are also other method to do it.
Like reverse the array, then shorten it, then revers again and then append.
What is a good way in terms of speed?
1