0
How can I add letters to this?
Here is a code? import java.util.HashMap; public class Solution { public static void main(String [] args){ HashMap<Integer, String> passportsAndNames= new HashMap<>(); passportsAndNames.put (123456, "Stive Carrol"); passportsAndNames.put (234567, "James Hope"); passportsAndNames.put (345678, "Herrard Alba"); System.out.println(passportsAndNames); } } Outputs: {123456=Stive Carrol, 234567=James Hope, 345678=Herrard Alba} The question is that how can I add letters before or after the numbers. Output should be like this: AA123456=Stive Carrol. Because passports usually consists of both numbers and letters.
2 Respuestas
+ 2
Then do this:
HashMap<String, String> p = new HashMap<>();
p.put("AA123456","Stive Carrol");
System.out.println(p);
+ 1
Thank you Namit Jain, now it outputs as I wanted