-3

I have a Map in a Servlet class which takes in an email (as a String) and a number of points (as an Integer) as a key and value, respectively.

Map<String,Integer> map = new HashMap<String,Integer>();

I want to read and write the contents of the Map into a file.

Also, every time the user inputs an email, I want to check if the email already exists. If it already exists then I need to add another 5 points to the user's points. If it doesn't exit, I should give him fres 5 points.

APerson
  • 8,140
  • 8
  • 35
  • 49

1 Answers1

0

You can reed how to open and write to a file here : How do I create a file and write to it in Java?

For the map logic :

int points = 5;

if (!map.containsKey(email)){
   points += map.get(email);
}

map.put(email, points);
Community
  • 1
  • 1
David Limkys
  • 4,907
  • 5
  • 26
  • 38