Not getting how to sort

Hey jayansh! I hope this helps.

Upvote if useful! Happy Coding! :slight_smile:

This might help…,if you are trying to sort an ArrayList of Strings

I found it very easy to work with and to understand

Use hashmap to store symbols along with close value and sort according to those close value. Then after sorting store the keys in an array list. That’s it.

thanks that worked for me

1 Like

Please mark it as a solution and close the thread.

Can you try to do some thing with total returns dto!!

In module 2 there is no file named total returns dto.
and @Jitender you’re posting solution here. Which is against community guidelines.

I don’t but It was visible to me, I used it actually.

I hope you clearly know the difference between solution and hints. I am not posting any code here. And tell me one thing what is the use of forums if you can’t give anyone a hint.

Ya sorry for the confusion you’re right there is totalReturns in dto directory.

@Jitender @jayansh i would recommend not using hashmap for starting. Why so, some people here itself can tell you. Although we are not that strict at this level in making fail for this task, but you might fail in later modules.

But don’t bother, in next module, you will anyways be introduced with cleaner ways to do the same

Sir what is the drawback of using hashmap here. Please clear my doubt.

It’s just that you’re over engineering stuff, It is good to use DTOs for data handling , it might ease up your test handling and stuff. and most importantly it will help you be more confident in OOPs concepts

@anuragq anything else?
Over engineering is one thing.
@akashchhetri can you please elaborate the use case you pointed to? It’s a valid scenario. Let’s discuss it here itself.

@anand-crio @Jitender @anuragq HashMap may lead to Data Loss/ Data overwrite if I map values on the same key (without using probing techniques). And If I use probing technique then It might happen It takes more time in searching. Although Java internally uses chain probing technique and also uses hashcode mechanism for each object to map as <key, value> pair.

Suppose, there are two individuals name “x” and “y” and their mother distributed 21 rs (10.5 for each). So, the case is “x” has 10.5 rs and “y” also has 10.5 rs.
Now if I use map take my key as 10.5 and values mapped are “x” and “y”
then without probing :

You can visualize similar case here

1 Like

@akashchhetri Can you please give some hints on what to use . I am able to retrieve symbol along with close price. But what to use and hiw to sort is still a question for me

Yes sure check java files under dto directory you may find one file which you can use in this module see hint on this comment

And there is a technique to sort objects based on some field values in java ascending and descending for both.

1 Like

Hey @akashchhetri. I tried using totalreturnsdto but i am not able to get output as required
I am trying to create ArrayList of totalreturndto. Is it correct?

Yes it is, Now use stack overflow link I mentioned above to to see how to sort ArrayList of Objects.

But when i am trying to use listname[index].getSymbol() I am getting error