You need to sign in to do that
Don't have an account?
naveen darshanala
How to create a Map to store both string and Integer?
I have requirement where I need to create a map with values can be either string or Integer. Could someone please let me know how to approach?
*You can Create map of both String and Integer, just keep sure that your key is Unique.
Note: A map is a collection of key-value pairs where each unique key maps to a single value
Map<integer,String> integer_String_Map = New Map<Integer,String>();
::
::
<Key,Value>(pair)
* You can access string using integer or you can reverse the map if you need that way:
Map<String,Integer> integer_String_Map = New Map<String,Integer>();
::
::
<Key,Value>(pair)
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
I am not expecting this answer, hope you didnt get my question,
I need to create map in such a way that - in value field it should accomodate both string and integer., imy scenario is like i need to store the values coming from order object,
so for example , i need to store name: which is string
and then i need to store total amount which is a decimal.. etc etc
I have gone through your problem please refer bellow code:
Apex class:-
public class TestMap {
public static void maptest(){
Map<Integer,String> lmap=new Map<Integer,String>();
lmap.put(1,'Abc');
lmap.put(2,'XYZ');
System.debug(lmap);
}
}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com