You need to sign in to do that
Don't have an account?

How to use this
How to iterate through map
Map<Date, List<String>> m1=new Map <Date, List<String>>();
I had the list ,now how to papulate list inside the map..
How to do this....bit urgent...
Thanks
Use nested for-loops to construct your Lists and the put method to construct the map inside the loop.
This is an arbitrary bit of code, since I don't know what you're exactly doing, but this is the code to construct your map<date, list<string>>.
Can u explane more
The get method of Map returns a data type value equal to the template parameter that you pass into it.
Consider this example:
What are the values contained in list_a, list_b, and list_c at this point in the code?
If you said that there were three "empty lists", you would be incorrect. In truth, you have not yet created (instantiated) the list (called an object), and so there is no memory associated with the list, and it is unable to call any of its instance methods. As another short example, consider the class:
To use this object, i first have to allocate memory to it through the process of "instantiation". However, the "static" members are freely available to me, even without instantiation. That means I can use the class like this:
If I remove the new HelloWorld() part of the above code, what is the result? Of course, there is no object, so the line after fails with an exception, because it can't operate without an instance.
Now, you might ask, what was the point of the preceding text? The answer is, of course, that Maps are almost exactly like infinitely sized lists, but using letters instead of numbers They never complain if you refer to an object that does not exist, they simply return a null value.
In my example above, it is therefore necessary that the list is instantiated before we attempt to use it, or you will observe the same problem as I've outlined. The previous poster mentioned also that you could use two loops to create your Map. The primary inconvenience with that is when you can not reliably determine which dates will be used in advance.
For example, if we do the following:
This certainly works (although it uses a query redundantly). We can optimize this one of two ways:
1) We cache the query, as follows:
This is better, as it "saves a SOQL query", and it uses only one more script statement. On the downside, it also uses more "heap memory", because that list of tasks no longer gets to fluidly pass through an optimized query loop, but has to occupy its full girth of memory for the rest of its scope. We could add some tricks to conserve that memory and free it as early as possible, but it'd be better if that memory were never "used" to begin with.
Thus, you would want to take advantage of a for loop, but remember that an unused map key returns a null value, which we can't use without getting an exception.
This leads us to the next layer of evolution with optimizing our code:
Our new code uses one additional script line for the if statement for each unique due date that is queried by this call. However, we save our extra SOQL call, as well as our heap memory. The more duplicated the date fields are, the better script-line-counter performance we would have.
Finally, we could over-optimize and come up with the following code:
I would expect that no sane developer would use a ternary operator if they could help it, but if optimization were truly a concern, there's always ways to squeeze a bit more out of the system. This happens to use exactly the same number of script statements as the first script, with the memory usage of the prior script, all wrapped up in a tidy package. Just remember to comment code that looks like this, or you (or some other unfortunate developer) might have a wonderful time trying to debug code like this.
Just remember, you don't want your code to end up looking like this:
(This code from http://www0.us.ioccc.org/years.html, a website for developers to write purposefully difficult-to-read code, known as obfuscation).
Thanks,
Class A{
List <Account> accs=new List<Accoyunts>();
Iterator<Accounts> itr=acc.iterator();
while(itr.hasNext()){
Accounts acc1=litr.next();
AccountName=acc1.Name;
}
Class B{
List<String> AccountName;
}
Now my querry is how to get the List value in 2nd class.only the List value(i.e AccountName )