Thursday, October 19, 2017

URLify in java 8 style functional flavor


 Write a method to replace all spaces in a string with '%20'


Instead of using str.replaceAll("\\s", "%20"), here is a function. This exercise is to help learning.



public String URLifyJava8(String str) {
return str.chars()
.mapToObj(c -> (char) c)
.flatMap(c -> Character.isWhitespace(c)
? "%20".chars().mapToObj(ch -> (char) ch) : Stream.of(c))
.collect(Collector
.of(StringBuilder::new, StringBuilder::append,
(r1, r2) -> {
r1.append(r2);
return r1;
},
StringBuilder::toString, Collector.Characteristics.CONCURRENT));
}

62 comments:

  1. Excellent read, I just passed this onto a colleague who was doing a little research on that. And he just bought me lunch because I found it for him smile Thus let me rephrase that: Thank you for lunch!
    software development outsourcing company
 

    ReplyDelete
    Replies
    1. I am glad, you found it useful.

      Delete
    2. Great Article android based projects

      Java Training in Chennai Project Center in Chennai Java Training in Chennai projects for cse The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

      Delete
  2. Don't know, haven't faced such an issue before, but hope that solution of your works well under any circumstances. Literally, I'm not into these things that much, just new to java (entirely new-new, to be frank), so I'm just hanging around with this soft, trying to understand how things work manually. I had no practice on that before, but my knowledge of fundamentals are clear, so I have filled all the gaps with this resource on learn java explainjava.com/category/java/java-core/ so I have some solid confidence on that. But when I've wandered in this thread and seen what things you guys are doing here, it's pretty impressive

    ReplyDelete
  3. I like this post,And I guess that they having fun to read this post,they shall take a good site to make a information,thanks for sharing it to me.
    software development company in delhi

    ReplyDelete
  4. bike racks could really help you secure your bike when you leave it ,. stiply.nl elektronische handtekening

    ReplyDelete
  5. I just couldn’t depart your site prior to suggesting that I extremely enjoyed the standard information an individual provide for your visitors? Is gonna be back frequently in order to inspect new posts sd wan technology

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

    ReplyDelete
  7. very helpful information for coder, we will also apply this method when we face any problem, thanks for sharing this useful function code guide. web design services

    ReplyDelete
  8. Extremely pleasant article, I appreciated perusing your post, exceptionally decent share, I need to twit this to my adherents. Much appreciated!.  cisco meraki

    ReplyDelete
  9. This is what we call soothing and The blog is like a portal of feelings.
    outsourcing code development

    ReplyDelete
  10. I recently came across your blog and have been reading along. I thought I could leave my first comment. I don’t know what to say except that I have enjoyed reading what you all have to say https://www.btcsoftware.co.uk/making-tax-digital/

    ReplyDelete
  11. This is one of the best fashion tips for women ever. Most women have racks and racks of clothes hanging in their closets.  site here

    ReplyDelete
  12. Albeit electronic business causes the disintermediation of a few go-betweens, it makes more prominent reliance on others and furthermore some altogether new middle person capacities. Angular testing services software testing

    ReplyDelete
  13. This very popular service typically involves creating detailed test cases that not only can be used on the project under test, but also due to their high quality can be re-used on future projects and form a high quality test documentation asset.https://www.dbdesigner.net

    ReplyDelete
  14. They long for an operational course bookkeeping ERP software arrangement that encourages the gushing and dispersion of all inclusive data on each work area and cell phone. exercise prescription software

    ReplyDelete
  15. I just added this site to my google reader, excellent stuff. Can’t get enough! Online JSON Formatter

    ReplyDelete
  16. Both pay-per-click and SEO are targeted to get your website placed as close to the top of search engine results as possible. Marketing and SEO are different, yet very, very similar. pbn for sale

    ReplyDelete
  17. I was surfing net and fortunately came across this site and found very interesting stuff here. Its really fun to read. I enjoyed a lot. Thanks for sharing this wonderful information. https://www.redspider.ae/

    ReplyDelete
  18. I just got to this amazing site not long ago. I was actually captured with the piece of resources you have got here. Big thumbs up for making such wonderful blog page! pc monitor

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

    ReplyDelete
  20. Different societies and different people since the beginning have talked about and contemplated the need and approaches to accomplish personal development.מבחן אישיות

    ReplyDelete
  21. I would recommend getting a hosting company to host your blog, one that is friendly for your blogging platform. If this is not your area of expertise, there are video tutorials that will help you through the process step-by-step. hufforbes.com

    ReplyDelete
  22. Thank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our. coreldraw x7 free download

    ReplyDelete
  23. AOL is an online service provider which is very famous in the United States.You can actually resolve the solutions on your own but to save the time and frustration you can contact the AOL Support Number

    ReplyDelete
  24. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. I was exactly searching for. Thanks for such post and please keep it up. Great work. app cloner pro apk

    ReplyDelete
  25. wow this good but ,I like your post and good pics may be any peoples not like because defrent mind all poeple , wix vs shopify for ecommerce

    ReplyDelete
  26. It's a nice article, Which you have shared here about the URLify code. Your article is very informative and useful to know more about the process of implementing URLify code in Java8. Thanks for sharing this article here. software development company Phoenix

    ReplyDelete
  27. Technology creates along two ways - a developmental way and a progressive way.
    streaming microphone

    ReplyDelete
  28. java 8 is an amazing topic on which you have shared this information with us. I am also a developer & this is very helpful stuff for me as well. Adweb Dubai

    ReplyDelete
  29. I want you to thank for your time of this wonderful read!!! I definately enjoy every little bit of it and I have you bookmarked to
    check out new stuff of your blog a must read blog!!!! Golden Triangle India Tour

    ReplyDelete
  30. Its very good to see such a nice and informative article, this article really getting me an aspiration to do the same as you. Keep going on Admin and thank you for the content.
    seo Agency in Sharjah
    seo Agency in Dubai
    seo Agency in Ajman
    SEO Agency in Ras Al Khaimah
    SEO Agency in Abu Dhabi
    SEO Agency in Al Ain

    ReplyDelete
  31. Hi Admin thanks for providing such an informative article about the topic, actually I have read many articles but this is unique from others. Really I have enjoyed lot reading this. Thank you so much, keep sharing such nice articles.
    Desert Safari Dubai
    Desert Safari Sharjah

    ReplyDelete
  32. MLM Ready Made Software is a multi-level marketing solution that enables businesses to build and manage network marketing workflows using compensation plans, social media strategies and more. Built on the Laravel PHP framework, it uses back-end caching technologies to speed up processes across the organization MLM Ready Made Software offers a multi-currency module which allows businesses to process/receive payments in various currencies through different methods.
    MLM Ready Made Software
    Cryptocurrency MLM Software development company

    ReplyDelete
  33. The descriptive ideas presented in your article are shown with such enthusiasm that your passion has taken me over. I'll be forced to research more and try to learn more
    desert safari sharjah

    ReplyDelete
  34. It is truly a well-researched content and excellent wording. I got so engaged in this material that I couldn’t wait to read. I am impressed with your work and skill. Thanks. Read more info about Xml Beautifier

    ReplyDelete
  35. This article provided me with a wealth of information. The article is incredibly helpful and offers some of the most useful information. Thank you for sharing it with us. tool polishing India

    ReplyDelete
  36. Can I use CSS to change the style of my software? I'm afraid to use CSS lest my software license be invalidated. Buy Dissertation Online

    ReplyDelete
  37. Tree Hut’s Polishing and Hydrating Lip Scrub is a unique 2 in 1 formula that’s simple but packs a punch. Specially formulated with sugar to exfoliate and a blend of Organic Shea Butter with refreshing Peppermint Oil to nourish and soothe dry lips. Please Visit here:
    buff puff cleansing pads
    tifara beauty flexible curling rods,
    first aid beauty ultra repair cream mango
    The best part is it’s a leave on formula, after scrubbing, lick off the sugar and enjoy petal soft lips.

    ReplyDelete
  38. Very nice information, This information will always help everyone for gaining knowledge. So please always share your important information. I am very thankful to you for providing essential information. Thanks once again for sharing it. full stack development service

    ReplyDelete
  39. Thanks for sharing this article here about the church book publishing services. Your article is very informative and I will share it with my other friends as the information is really very useful. Keep sharing your excellent work.

    ecommerce services provider in india

    ecommerce solutions services

    ReplyDelete
  40. Very well written article. It was an awesome article to read. Complete rich content and fully informative. I totally Loved it.1040 prep outsource to India

    ReplyDelete
  41. I read this article. I think You put a great deal of exertion to make this article. I like your work. 먹튀검증사이트

    ReplyDelete
  42. I read this article. I think You put a great deal of exertion to make this article. I like your work. 꽁머니사이트

    ReplyDelete
  43. Ha ha… I was just surfing around and took a look at these reviews. I can’t believe that there’s still this much interest. Thanks for posting about this. 꽁머니사이트

    ReplyDelete
  44. organic foods and products promote environmentally sustainable, eco-friendly healthier use of natural resources for fit lifestyle ORGANIC FOODS AND PRODUCTS

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

    ReplyDelete
  46. As we have seen, I believe this article to be well-informed. The essay is helpful to us, and your writing style is extremely outstanding. Thank you for sharing this article.manga nato

    ReplyDelete