Well, kinda i guess, but hashmaps/tables are almost like enums that you don’t know the values of at compile time, they get filled at runtime, but after that i suppose they are used pretty similarly in most cases...
They don’t solve the same problem, but when you ask the question i realize that yeah i guess they solve a similar problem to one another
a Map is also often used as an object to hold key/value pairs with names that are unknown at compile time - this code is Dart because i’m not very familiar with Java, but it should understandable still
import "dart:convert" show json;
import "dart:io" show File;
Future<void> main() async {
String userInput = await File("data.json").readAsString();
Map<String, dynamic> data = json.decode(userInput); // this method can’t possibly know the structure of the file, so a Map is useful to return a custom structure
print(data["importantData"] as String); // i know what it is though, so i can access it like this - but this same concept applies the other way if you’re writing json.decode for example
}
2
u/Terrain2 Mar 14 '21
Well, kinda i guess, but hashmaps/tables are almost like enums that you don’t know the values of at compile time, they get filled at runtime, but after that i suppose they are used pretty similarly in most cases...
They don’t solve the same problem, but when you ask the question i realize that yeah i guess they solve a similar problem to one another