Thursday, 5 June 2014

Avoid duplicate string values in the collection 'Set' or 'Map Keys' while adding strings with different cases

When, Set allows duplicates?
Examples:

Set<String> nameSet = new Set<String>;
nameSet.add(srinu);
nameSet.add(SRINU);
nameSet.add(Srinu);

Map<String,String> cityMap = new Map<String,String>;
cityMap .put('Newyork', USA);
cityMap .put('newyork',US);
cityMap .put('NEWYORK','America');

From the above examples, nameSet and cityMap allows all the three values because set and map key treat the values with different case as different values that means set string values are case-sensitive.

How to avoid?
Use the below method before adding string value to set or map key.

//Generic method to search a string from set of strings and which will ignore case-sensitive
public static Boolean isStrExists(Set<String> strSet,String searchStr) {
        Boolean isTrue = false;
        if(strSet != null && strSet.size() > 0) {
            for(String strVal : strSet) {
                if(strVal.equalsIgnoreCase(searchStr)) {
                    isTrue = true;
                    break;
                }
            }
        }
        return isTrue;
    }

How to use above method?
if(!isStrExists(nameSet,'SRINU'))
    nameSet.add('SRINU');

88 comments:

  1. Excellent post!!! The future of cloud computing is on positive side. With most of the companies integrate Salesforce CRM to power their business; there is massive demand for Salesforce developers and administrators across the world. Salesforce Training Institutes in Chennai

    ReplyDelete
  2. In coming years, cloud computing is going to rule the world. The cloud based CRM tool provider like Salesforce have massive demand in the market. Thus talking Cloud Computing Training in Chennai from reputed Cloud Computing Courses will ensure bright career prospects for aspiring professionals.

    ReplyDelete
  3. Very interesting and good article, it is very useful to me... keep rocks.. thanks for sharing your valuable time and views....

    Salesforce Training in chennai | Salesforce Training in velachery

    ReplyDelete
  4. Excellent blog which helps me to get the in depth knowledge about the technology, Thanks for sharing such a nice blog. MCSE Training Institute in Chennai | MCSA Training Institute in Chennai | Hardware & Networking Training in Chennai

    ReplyDelete
  5. The best thing is that your blog really informative thanks for your great information..Final Year Project Center in Chennai | Final Year Project Center in Velachery

    ReplyDelete
  6. Great tips and its so easy to understand. Kindly keep updating such a nice article..
    PCB Training Institute in Chennai | PCB Training Center in Chennai | PCB Training in Velachery

    ReplyDelete
  7. Awesome Blog, you have provided the right information that will be beneficial to us. Thanks for sharing your valuable Ideas to our vision. Linux Training in Chennai | Unix Training in Chennai | Python Training in Chennai

    ReplyDelete
  8. Thanks for this blog. provided great information. All the details are explained clearly.
    Robotics Training Center in Chennai | Robotics Project Center in Chennai | Robotics Training in Velachery

    ReplyDelete
  9. • Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your blog? My blog is in the same niche as yours, and my users would benefit from some of the information you provide here. Please let me know if this ok with you. Thank you."Devops Training in Chennai"

    ReplyDelete
  10. Thanks for posting this useful and informative article with impressive content..keep updating..Diploma Project Center in Chennai | Diploma Project Center in Velachery

    ReplyDelete
  11. I really understand the concepts clearly..Thanks for giving such a nice post..
    Best Real Time Project Center in Chennai | Real Time Project Center in Velachery

    ReplyDelete
  12. I really understand the concepts clearly..Thanks for giving such a nice post..Six Sigma Certification Training in Chennai | Six Sigma Exam Center in Velachery

    ReplyDelete
  13. Very interesting content which helps me to get the in depth knowledge about the technology. To know more details about the course visit this website.Final Year Project Center in Chennai | Best Project Center in Chennai | No.1 Final Year Project Center in Chennai | Best Project Center in Velachery

    ReplyDelete
  14. I simply wanted to thank you so much again. I am not sure the things that I might have gone through without the type of hints revealed by you regarding that situation

    python training in marathahalli

    ReplyDelete
  15. I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.
    Robotics Training Center in Chennai | Robotics Project Center in Velachery

    ReplyDelete
  16. Good post and I like it very much. By the way, anybody try this increase app downloads? I do not how to use.

    ReplyDelete
  17. Hi, am a big follower of your blog. I am really happy to found such a helpful and fascinating post that is written in well manner.
    mobile website builder

    ReplyDelete
  18. You have done a great job, really the salesforce interview question was useful to us, Thank you for sharing such a useful information.. Keep updating such a nice blog..Automation Anywhere Training in Chennai | RPA Training Institute in Chennai | UI Path Training Institute in Chennai | Blue Prism Training Institute in Chennai

    ReplyDelete
  19. Very Useful information that i have found. don't stop and Please keep updating us..... ThanksJava Training in Chennai | Web Designing Training Institute in Chennai | DotNet Training Institute in Chennai

    ReplyDelete
  20. I have a nice posting helpful very awesome article great blog please
    information help you.
    Best Adobe Photoshop Training Institute in Chennai | No.1 CorelDraw Training Institute in Chennai

    ReplyDelete
  21. I am really happy to read your blog..Thanks for posting this informative post..
    Power System Project Center in Chennai | Power System Projects in Velachery

    ReplyDelete
  22. Nice post.. Really you are done a wonderful job. Thanks for sharing such wonderful information with us. Please keep on updating..
    Best Microsoft Azure Training Institute in Chennai | Best Microsoft Azure Training Institute in Velachery

    ReplyDelete
  23. Nice post.. Really you are done a wonderful job. Thanks for sharing such wonderful information with us. Please keep on updating..
    Best VMware Training Institute in Chennai | Best VMware Training Institute in Velachery

    ReplyDelete
  24. I feel really happy to have seen your webpage and look forward to so
    many more entertaining times reading here. Thanks once more for all
    the details.

    white label website builder

    ReplyDelete
  25. I strongly believe that there will be good opportunities for those who looked at your site.
    Best Online Software Training Institute | Salesforce.com Integration Training

    ReplyDelete
  26. Congrats for your work. Thanks a lot for providing this with us. Keep on updating this with us regularly..
    ISTQB Certifications Exam institute in Chennai | QA Testing in Sholinganallur

    ReplyDelete
  27. Nice post.Thanks for sharing this post .I really appreciate the kind of topics you post here.
    Android Certifications Center in Chennai | No.1 Android Exam in Saidapet

    ReplyDelete
  28. Nice information about this valuable article,which helps to learn more....
    Real Time Project Center in Chennai | Real Time Project in Kanchipuram

    ReplyDelete
  29. Nice tutorial. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful.
    Devops Training in Chennai | Devops Training Institute in Chennai

    ReplyDelete
  30. very nice blogs!!! i have to learning for lot of information for this sites...Sharing for wonderful information. Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing

    Best AWS Training Academy in Kanchipuram

    ReplyDelete
  31. Really very great information to be provided and the All points discussed were worth reading and i’ll surely work with them all one by one.
    Best C and C++ Programming Training Academy in Kanchipuram

    ReplyDelete
  32. Awesome post. Really you are shared very informative concept... Thank you for sharing. Keep on updating...

    Best Graphics Designing Training Academy in Kanchipuram

    ReplyDelete
  33. Wonderful post. Thank you for updating such an informative content.

    Best Python Training Academy in Kanchipuram

    ReplyDelete
  34. Thanks for this greatful information. all this information is very important to all the users and can be used good at all this process
    Best Tally ERP 9.0 Training Academy in Kanchipuram

    ReplyDelete
  35. really you have posted an informative blog. it will be really helpful to many peoples. thank you for sharing this blog. so keep on sharing such kind of useful blogs.

    Best TALLY ERP 9.0 Training Academy In Kanchipuram

    ReplyDelete
  36. Your article was so impressive and informative. Its very interesting to read. Thanks for sharing,
    Best web design Training Institute in Kanchipuram

    ReplyDelete
  37. thank you for such a great article with us. hope it will be much useful for us. please keep on updating..
    Best software testing Training Institute in Kanchipuram

    ReplyDelete
  38. Thanks for posting this article.
    Unicsol offers Best full stack developer course in hyderabad get trained by 10+years of experienced faculty and get placed as full stack developer.

    ReplyDelete
  39. I think this is an informative post and it is very useful and knowledgeable. I really enjoyed reading this post. thank you!
    Best Python Course Training Institute in kanchipuram|

    ReplyDelete
  40. The best thing is that your blog really informative thanks for your great information
    Best tally erp 9 Course Training Institute in kanchipuram|

    ReplyDelete
  41. Awesome Blog with informative concept. Really I feel happy to see this useful blog, Thanks for sharing such a nice blog...
    Best Linux Certification Course Training Institute in kanchipuram|

    ReplyDelete
  42. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Best UIPath Robotic Process Automation Course Training Institute in kanchipuram|

    ReplyDelete
  43. Excellent post. I have read your blog it's very interesting and informative. Keep sharing.
    Best JAVA / J2EE / J2ME Course Training Institute in kanchipuram|

    ReplyDelete
  44. Nice post.. Really you are done a wonderful job. Thanks for sharing such wonderful information with us. Please keep on updating...
    Best C & C++ Course Training Institute in kanchipuram|

    ReplyDelete
  45. Very nice post here and thanks for it .I always like and such a super blog of these post.Excellent and very cool idea and great blog of different kinds of the valuable information's.
    Best Tally Erp 9.0 Course Training Institute in kanchipuram|

    ReplyDelete
  46. I feel satisfied with your blog, you have been delivering useful & unique information to our vision even you have explained the concept as deep clean without having any uncertainty, keep blogging.
    No:1 Tally Training Academy in kanchipuram

    ReplyDelete
  47. This is really impressive post, I am inspired with your post, do post more blogs like this, I am waiting for your blogs.
    Best Tally Erp 9.0 Course Training Institute in kanchipuram|

    ReplyDelete
  48. Interesting post!!! Thanks for posting such a useful information. I wish to read your upcoming post to enhance my skill set and keep blogging.
    Best Tally Erp 9.0 Course Training Institute in kanchipuram|

    ReplyDelete
  49. This is excellent information. It is amazing and wonderful to visit your

    site.Thanks for sharing this information, this is useful to me.
    Best Selenium

    Automation Course Training Institute in kanchipuram
    |

    ReplyDelete
  50. Very good and informative information. Thanks for sharing such nice blog, keep on updating such good post.
    Best Software Testing Course Training Institute in kanchipuram|

    ReplyDelete
  51. I have read your blog. Good and more information useful for me, Thanks for sharing this information keep it up....
    Best Dot Net Course Training Institute in kanchipuram|

    ReplyDelete
  52. Excellent post!!! The future of cloud computing is on positive side. With most of the companies integrate Salesforce to power their business; there is massive demand for Salesforce developers and administrators across the world.
    No:1 BBA Project Center in kanchipuram

    ReplyDelete
  53. Really it was an awesome blog...very interesting to read..You have provided an nice information....Thanks for sharing..
    Best Hardware & Networking Course Training Institute in kanchipuram|

    ReplyDelete
  54. Thanks for the useful information of software testing courses, give more updates on software testing development, First time I visit your blog really nice, I bookmark your blog here after a daily visit. Learn
    No:1
    Java J2EE Training Academy in kanchipuram

    ReplyDelete
  55. Nice blog. Thank you for sharing. The information you shared is very effective for learners I have got some important suggestions from it.
    Best PCB (Printed Circuit Board) Course Training Institute in kanchipuram|

    ReplyDelete
  56. Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.
    Best PCB (Printed Circuit Board) Course Training Institute in kanchipuram|

    ReplyDelete
  57. Nice blog. Thank you for sharing. The information you shared is very effective for learners I have got some important suggestions from it.
    No:1 Hardware and Networking Training Academy in Kanchipuram

    ReplyDelete
  58. I love reading and following your post as I find them extremely informative and interesting.
    Best AWS (Advanced Amazon Web Services) Course Training Institute in kanchipuram|

    ReplyDelete
  59. Awesome post. Really you are shared very informative information... Thank you for sharing. Keep on updating...
    Best AWS (Advanced Amazon Web Services) Course Training Institute in kanchipuram|

    ReplyDelete
  60. Nice blog. Thank you for sharing. The information you shared is very effective for

    learners I have got some important suggestions from it.
    No:1 Azure Training Academy in

    Kanchipuram


    ReplyDelete
  61. Great post..Its very useful for me to understand the information..Keep on blogging..
    Best Software Testing Course Training Institute in kanchipuram|

    ReplyDelete
  62. Nice..You have clearly explained about the conept..Its very useful for me to undertand..Keep on sharing..

    No:1 Azure Training Academy in Kanchipuram



    ReplyDelete
  63. I found some useful information in your blog, it was awesome to read, thanks for sharing this great information to my vision, keep sharing.
    Best Graphic Designing Course Training Institute in kanchipuram|

    ReplyDelete
  64. This comment has been removed by the author.

    ReplyDelete
  65. Marvelous and fascinating information.Thanks for this greatful blog. keep your blog updated.
    Best Hardware & Networking Course Training Institute in kanchipuram|

    ReplyDelete
  66. Thanks a lot for offering this unique post with us. I really enjoyed by reading your blog post.keep sharing.
    Best Python Course Training Institute in kanchipuram|

    ReplyDelete
  67. This is really awesome. Full of knowledge and latest information.Thanks for sharing.
    Best JAVA / J2EE / J2ME Course Training Institute in kanchipuram|

    ReplyDelete
  68. great and nice blog thanks sharing..I just want to say that all the information you have given here is awesome...Thank you very much for this one.
    No:1 Best EEE Project Center in kanchipuram|

    ReplyDelete
  69. really you have posted an informative blog. it will be really helpful to many peoples. thank you for sharing this blog. so keep on sharing such kind of useful blogs.
    No:1 Best NS2 (Network Simulator) Project Center in kanchipuram|

    ReplyDelete
  70. The provided information’s are very useful to me.Thanks for sharing.Keep updating your blog.

    No:1 Networking project Centre in kanchipuram

    ReplyDelete
  71. very usefull informatation.and iam expecting more posts like this please keep updating us....
    No:1 Best Android Project Center in kanchipuram|

    ReplyDelete
  72. Thanks for this greatful information. all this information is very important to all the users and can be used good at all this process.please keep on updating..
    No:1 Best ECE ( Electronics & Communications Engineering) Project Center in kanchipuram|

    ReplyDelete
  73. You post explain everything in detail and it was very interesting to read.Thank you for Sharing.
    No:1 Best Dotnet Project Center in kanchipuram|

    ReplyDelete