MRU Page Replacement Java
<p>I'm supposed to be going through an array of these numbers, 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 then putting the first (non-repeating numbers) into a smaller array that holds only 5 of the numbers.  </p>

<p>So after the first five are in, it would look like 7 0 1 2 3 (since 0 was already present within the array).  </p>

<p>Then its supposed to search through and compare each element in the rest of the larger array with every element in the smaller one.  T</p>

<p>The next element in the larger array is 0, the program needs to compare 0 to all the elements in the smaller array.  </p>

<p>If the element exists in the smaller array, its just supposed to set a MRU variable equal to the index of the element that exists within the smaller array.  </p>

<p>If the number doesn't exist, say like after the next run, 4. Then the program will replace the element at the MRU variable with the number 4. </p>

<p>I have two questions, </p>

<ol>
<li>this program just spits back out to me the original numbers and idk, why?  </li>
<li>where do i go from here?  </li>
</ol>

<p>I've worked on this for many days and gone through countless variations.  Its already passed the due date, but I want to learn how to do this.          </p>

<pre><code>   import java.util.*;
   import java.io.*;

   public class MRUPageReplacement
   {
    public static void main(String [] args)
   {
  //======== Variables ==============================================
     ArrayList&lt;Integer&gt;MRUList = new ArrayList&lt;Integer&gt;();
     int [] frames = {7,0,1,2,3};
     int i,j,MRU;
     String line;


  //======== File Reader ============================================
     try
     {      
        FileReader reader = new FileReader("MRU.txt");      
        BufferedReader r = new BufferedReader(reader); 
        while ((line=r.readLine())!=null)
        {
           MRUList.add(Integer.parseInt(line));
        }
     }
        catch(Exception e)
        {
           System.out.println("File Not Found");
        } 

     int[] array = new int [MRUList.size()];
     for (i =0; i &lt; MRUList.size(); i++)
     {
        array[i] =  MRUList.get(i);
     } 

  //======== Fill Arrays ============================================== 


  //======== Compare ==============================================       
     for(i=0; i&lt;array.length; i++) 
        {     // Iterate through the array
        for( j=0; j&lt;frames.length; j++) 
            {   // Iterate through frames
           if(array[i] == frames[j]) 
                {
            // if the element is in frames
            MRU = j;
           }
           else {
           // if the element is not in frames
            frames[MRU] = array[i];   

           }
        }
     }


  /*======== Print ==============================================
     for(i=0; i&lt;frames.length; i++)
     {
        System.out.println("frames : " + frames[i]);
     }  
  */

  }
}




// Sample output
frames : 7
frames : 0
frames : 1
frames : 2
frames : 3
frames : 0
frames : 0
frames : 1
frames : 2
frames : 3
frames : 0
frames : 1
frames : 1
frames : 2
frames : 3
frames : 0
frames : 1
frames : 2
frames : 2
frames : 3
frames : 0
frames : 1
frames : 2
frames : 2
frames : 3
frames : 3
frames : 1
frames : 2
frames : 2
</code></pre>

<p>On a side note, when I try and print out the array instead of just the numbers it gives this: [I@565b540e.  Is that because it's printing the index?</p>

<p>Eventually I would like to print out the frames array each time it runs through. Like:
Run 1: Frames = {70123}.</p>

<p>EDIT: Ok so after some amazing help from Noctua, im now running into the main problem i was having before.  It only recognizes the first or second iteration i can't tell since the second number is supposed to be a zero.  Here is the part thats messing up:</p>

<pre><code>for(i=0; i&lt;array.length; i++) 
     {     // Iterate through Array 
        for( j=0; j&lt;frames.length; j++) 
        {   // Iterate through Frames 
           if(array[i] == frames[j]) 
           {
            // Item from Array exists in Frames
              MRU = j;
              MRU_found = true;
           }
        }
        if(!MRU_found) 
            {
           frames[MRU] = array[i];
        }
</code></pre>

<p>I've worked at it from a couple angles, however nothing seems to be working.     </p>
