I see plenty of references to String datatypes, but is there a String datatype as well for with key-value pairs in the Apex coding language?

The original C# language has them here: https://msdn.microsoft.com/en-us/library/xfhwa508(v=vs.110).aspx

Javascript has them here: https://stackoverflow.com/questions/7196212/how-to-create-dictionary-and-add-key-value-pairs-dynamically


We refer to dictionaries as a Map. The general form of this Map<T, U>, where T is almost any data type (except Void), and U is any data type (except Void). Type T is the type of of key, and type U is the type of the value. So for a key-value pair of String-String, you would say Map<String, String>, and for a map of, say, numbers to Strings, you can say Map<Integer, String>. You can learn more about Maps in the documentation.

Edit: Map<T, void> for any type T now throws an Internal Server error, although it's allowed to compile.

  • Ah, thanks sfdcfox. That seriously is a big help. Really appreciate it. – xorLogic Aug 12 '18 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.