Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Java equivalent for PHP array with non-numeric keys?

What would be Java equivalent for php array like this:

$user = array("name" => "John", "email" => "[email protected]");
like image 467
bancer Avatar asked Nov 28 '22 15:11

bancer


1 Answers

You can use a HashMap or a Hashtable. Not sure which one to use? Read the API or check out this question which discusses the pros and cons of each.

HashMap<String, String> map = new HashMap<String, String>();
map.put("name", "John");
map.put("email", "[email protected]");
like image 197
Catchwa Avatar answered Dec 10 '22 01:12

Catchwa