function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rahul MahaleRahul Mahale 

need to print Key & Values line by line

I need to print in O/P of  Stored values in Keys & Associated values line by line of Map function.

o/p required :

the current key =98
the current value for above key = Robert

What enhancement should i do to achieve o/p?

Code :

//Declare Map Variable & Show key Values, Values & Check if it is empty or not.

Map<integer, String> VarMapOfEmployeeMobileNum= New Map <integer, String>();

//add some items
VarMapOfEmployeeMobileNum.put(98,'Robert');
VarMapOfEmployeeMobileNum.put(64,'Matthew');
VarMapOfEmployeeMobileNum.put(55,'Harry');

//to see the map
System.debug('The current map ='+VarMapOfEmployeeMobileNum);


//Collect all Keys and Show 1 By 1
set<Integer> VarTempSet = new set<Integer>();
VarTempSet = VarMapOfEmployeeMobileNum.keyset();
for (integer VarMobileSetPrint: VarTempSet)
{
    system.debug('The Current Key ='+VarMobileSetPrint);
}

//Collect all Values and Show 1 By 1
List<String> VarTempList = new List<String>();
VarTempList = VarMapOfEmployeeMobileNum.Values();
for (string VarMobileListPrint: VarTempList)
{
    system.debug('The Current Value for above Key ='+VarMobileListPrint);
}
 
Best Answer chosen by Rahul Mahale
ravi soniravi soni
Hi Rahul,
try following code.
Map<integer, String> VarMapOfEmployeeMobileNum= New Map <integer, String>();

//add some items
VarMapOfEmployeeMobileNum.put(98,'Robert');
VarMapOfEmployeeMobileNum.put(64,'Matthew');
VarMapOfEmployeeMobileNum.put(55,'Harry');

//to see the map
System.debug('The current map ='+VarMapOfEmployeeMobileNum);
for (integer key: VarMapOfEmployeeMobileNum.keyset()){
    system.debug('The Current Key ='+key);
    
         system.debug('The Current value ='+ VarMapOfEmployeeMobileNum.get(key));
    }

get value based key.
I hope above info will help you and if it help, let me know to mark it as best answer.
Thank you

All Answers

Suraj Tripathi 47Suraj Tripathi 47
Hi,

Please replace your code with below code:-
public class mapValues {
    public static void disp(){
        Map<integer, String> VarMapOfEmployeeMobileNum= New Map <integer, String>();
        
        //add some items
        VarMapOfEmployeeMobileNum.put(98,'Robert');
        VarMapOfEmployeeMobileNum.put(64,'Matthew');
        VarMapOfEmployeeMobileNum.put(55,'Harry');
        
        //to see the map
        System.debug('The current map ='+VarMapOfEmployeeMobileNum);
                for (integer  i : VarMapOfEmployeeMobileNum.keyset())
        {
            system.debug('The Current Key ='+i);
            system.debug('The Current Value for above Key ='+VarMapOfEmployeeMobileNum.get(i));
            
        }
    }
}


Please mark it as Best Answer if it helps you.

Thanks & Regards
Suraj Tripathi
ravi soniravi soni
Hi Rahul,
try following code.
Map<integer, String> VarMapOfEmployeeMobileNum= New Map <integer, String>();

//add some items
VarMapOfEmployeeMobileNum.put(98,'Robert');
VarMapOfEmployeeMobileNum.put(64,'Matthew');
VarMapOfEmployeeMobileNum.put(55,'Harry');

//to see the map
System.debug('The current map ='+VarMapOfEmployeeMobileNum);
for (integer key: VarMapOfEmployeeMobileNum.keyset()){
    system.debug('The Current Key ='+key);
    
         system.debug('The Current value ='+ VarMapOfEmployeeMobileNum.get(key));
    }

get value based key.
I hope above info will help you and if it help, let me know to mark it as best answer.
Thank you
This was selected as the best answer
movieseries movieseriesmovieseries movieseries
Media 123Movies streaming is a generation that has been drastically boosted by means of restricted bandwidths in the network, however which begins on the nearby device: At its center, the most effective issue that subjects is that an audio or video record from the player (123Movies streaming patron, renderer) is not absolutely loaded however arrives there in a consistent float of small facts packets. This has the decisive gain that playback can start right now despite the commonly very massive quantities of records. Videos from the internet or videos on call for cannot be found out in any other way with limited bandwidth.  In addition, such 123 movies streaming guarantees in exercise (but not in precept) for online video stores, for example, that the consumer tool only receives a few temporary information, however no longer the entire media item.
 
normantons normantonsnormantons normantons
Once get into the normanton park balance units (https://www.normantons-park.com/balance-units-chart/, you can likewise get to find out about the Normanton park showflat whenever. By visiting there, you will get a chance with regards to the business city in an immense level. In any event, as per that, it is consistently conceivable to push forward and this is the thing that large number of them are anticipating. The best thing about this park is the place where individuals might encounter voyaging advantageous with practically no issues without a doubt. Prior to that, try to contact the specialists and utilize it that at whatever point required.


 
pilip sheridanpilip sheridan
Thanks for this code to help us out of the problem. (https://www.myloweslifes.us/)
Christopher Smith 81Christopher Smith 81
Facing the Same Problem earlier but now it's Solved 100% https://shareitapk.org/ (https://shareitapk.org) by reading this Thread. 
Christopher Smith 81Christopher Smith 81
Facing the Same Problem earlier, but now it's Solved 100% https://tvtapapk.co/it/tvtap-pro-apk/ by reading this Thread.
Mannu GautamMannu Gautam
Here is what you should know about Indian news for different Hindi Yojana (http://allhindiyojna.in) and Mod apk Websites such as Download Mod Apk (http://downloadmodapkhub.com), Kinemater Mod Apk (http://kinemastermod.download)