I'm working on little "project" for saving some data in a Hashmap which I want to print out later in my console. I've almost finished with the whole code but I'm having problems with giving it out in my console... My code so far is:
import java.util.HashMap;
import java.util.Scanner;
public class Passwordsaver` {
public static void main(String[] args) throws InterruptedException {
// declare the hashmap
HashMap<Integer, String> Password = new HashMap<>();
boolean loopAgain = true;
Scanner scan = new Scanner(System.in);
// loop while user not entering no
do {
// ask for account (page)
System.out.print("Enter Page:");
String page = scan.nextLine();
// ask for password
System.out.print("Enter Password");
String password = scan.nextLine();
// add the key value pair from user input to the hashmap
String oldVal = password + page;
if (oldVal!=null) {
System.out.println("The password for the page: " + page + " is "
+ password + " and will be overwritten if entered again");
}
// ask user to check if another entry is required
System.out.print("Enter another account (y/n)?");
String answer = scan.nextLine();
// condition to satisfy in order to loop again
loopAgain = (answer.equals("y") || answer.equals("Y"));
} while (loopAgain);
scan.close();
System.out.println("\n**********************************");
System.out.println("The following accounts are in database");
System.out.println(" account "+ " password");
for(int page:Password.keySet()){
System.out.println(" "+ Password +" "+Password.get(page));
}
System.out.println("\n**********************************");
}
}
Everything works except the last step...How can I print it? Is there also a possibility to save the data so at a later time I can still change the map without having Eclipse opened the whole time?
Many thanks in advance!!!