title: How do I remove the last input from java HashMap using LinkedHashMap?
body: <p>I need the last input from HashMap to be deleted then, add a new input instead.I heard you can do that using LinkedHashMap, but how exactly? The instructions didn't mention that I should use LinkedHashMap but apparently, it is impossible to remove the last item from a HashMap without it.</p>
  <p>Or if you have any alternative solutions that would remove the last item so I could add the other input, do tell me what I should add to the code.</p>
  <p>Here is what I am trying to do:</p>
  <pre><code>package studentlist;
  import java.util.LinkedHashMap;
  import java.util.HashMap;
  import java.util.Map;
  import java.util.Scanner;
  
  public class StudentList {
  
      public static void main(String[] args) {
          
          Map&lt;String, String&gt; students = new HashMap&lt;&gt;();
          
          Scanner s = new Scanner(System.in);
          
          for(int i=1; i&lt;= 3; i++){
               
              System.out.print(&quot;Enter student number &quot; + i + &quot;: &quot;);  
              String es = s.nextLine();
              
              System.out.print(&quot;Enter student first name &quot; + i + &quot;: &quot;);
              String en = s.nextLine();
              
              students.put(es, en);
              
          }
        
          for (Map.Entry mp : students.entrySet()) {
              System.out.println(mp.getKey()  +  &quot; &quot;  + mp.getValue());
          }
        
          //The 3rd input should be removed before this:
  
          System.out.print(&quot;Enter your student number: &quot;);  
          String sn = s.nextLine();
              
          System.out.print(&quot;Enter your first name: &quot;);
          String fn = s.nextLine();
              
          students.put(sn, fn);
              
          for (Map.Entry mp : students.entrySet()) {
              System.out.println(mp.getKey()  +  &quot; &quot;  + mp.getValue());
          }
      }
  }
  </code></pre>