Java, Shifting Elements in an Array

Assuming your array is {10,20,30,40,50,60,70,80,90,100} What your loop does is: Iteration 1: array[1] = array[0]; {10,10,30,40,50,60,70,80,90,100} Iteration 2: array[2] = array[1]; {10,10,10,40,50,60,70,80,90,100} What you should be doing is Object temp = pool[position]; for (int i = (position – 1); i >= 0; i–) { array[i+1] = array[i]; } array[0] = temp;

What is the difference between an Abstract Data Type(ADT) and a Data Structure?

This may help: To put it simple, ADT is a logical description and data structure is concrete. ADT is the logical picture of the data and the operations to manipulate the component elements of the data. Data structure is the actual representation of the data during the implementation and the algorithms to manipulate the data … Read more

How to implement a most-recently-used cache

Java Collections provide LinkedHashMap out of the box, which is well-suited to building caches. You probably don’t have this in Java ME, but you can grab the source code here: http://kickjava.com/src/java/util/LinkedHashMap.java.htm If you can’t just copy-paste it, looking at it should get you started implementing one for inclusion in your mobile app. The basic idea … Read more