I need to do changes just on specific wordsHow do I generate random integers within a specific range in Java?How to upper case every first letter of word in a string?Is null check needed before calling instanceof?Capitalize only the First Letter in a String javaRecognizing and replacing parts of a string in java 7Check String for Uppercase letter and find positionMaking only the first letter of a word uppercasegrouping words by first characterconvert to capital letter using java 8 streamConverting given string to camel case recursively

What are the advantages of luxury car brands like Acura/Lexus over their sibling non-luxury brands Honda/Toyota?

Adding command shortcuts to /bin

Start job from another SQL server instance

As a GM, is it bad form to ask for a moment to think when improvising?

Which sphere is fastest?

What was the first story to feature the plot "the monsters were human all along"?

Install LibreOffice-Writer Only not LibreOffice whole package

Can you use "едать" and "игрывать" in the present and future tenses?

Why didn't this character get a funeral at the end of Avengers: Endgame?

Why did the Apollo 13 crew extend the LM landing gear?

Endgame puzzle: How to avoid stalemate and win?

Why do these characters still seem to be the same age after the events of Endgame?

Should I simplify my writing in a foreign country?

How can I get people to remember my character's gender?

Is there a word that describes the unjustified use of a more complex word?

Copy previous line to current line from text file

Should homeowners insurance cover the cost of the home?

Notation: What does the tilde bellow of the Expectation mean?

Why does sound not move through a wall?

Hostile Divisor Numbers

Is Benjen dead?

How do I calculate how many of an item I'll have in this inventory system?

Where are the "shires" in the UK?

It is as simple as ABC



I need to do changes just on specific words


How do I generate random integers within a specific range in Java?How to upper case every first letter of word in a string?Is null check needed before calling instanceof?Capitalize only the First Letter in a String javaRecognizing and replacing parts of a string in java 7Check String for Uppercase letter and find positionMaking only the first letter of a word uppercasegrouping words by first characterconvert to capital letter using java 8 streamConverting given string to camel case recursively






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















I have a String problem for the Java 8 streams. They want me to change all the first letter into uppercase letter just if the words aren't into "the", "a", "to", "of", "in" group.



My problem is that the filter command does delete the words from the group and I have to keep them.



I have already done the part for the upper case first letter but I have no idea how to make the "jump" over the group of words



private List<String> ignoredWords = Arrays.asList("the", "a", "to", "of", "in");
String entryParts[] = toTitlelize.split(" ");

List<String> sentenceParts = Arrays.asList(entryParts);
List<String> finalSentence = sentenceParts.stream()
.map(WordUtils::capitalize)
.collect(toList());


For example :



if toTitlelize = "I love to eat pizza in my home"


It should return




"I Love to Eat Pizza in My Home"




for the moment it gives me:




"I Love To Eat Pizza in My Home"











share|improve this question



















  • 1





    You can choose to implement capitalize in such a way that it ignores the words from ignoredWords collection as well.

    – Naman
    Mar 23 at 3:04

















2















I have a String problem for the Java 8 streams. They want me to change all the first letter into uppercase letter just if the words aren't into "the", "a", "to", "of", "in" group.



My problem is that the filter command does delete the words from the group and I have to keep them.



I have already done the part for the upper case first letter but I have no idea how to make the "jump" over the group of words



private List<String> ignoredWords = Arrays.asList("the", "a", "to", "of", "in");
String entryParts[] = toTitlelize.split(" ");

List<String> sentenceParts = Arrays.asList(entryParts);
List<String> finalSentence = sentenceParts.stream()
.map(WordUtils::capitalize)
.collect(toList());


For example :



if toTitlelize = "I love to eat pizza in my home"


It should return




"I Love to Eat Pizza in My Home"




for the moment it gives me:




"I Love To Eat Pizza in My Home"











share|improve this question



















  • 1





    You can choose to implement capitalize in such a way that it ignores the words from ignoredWords collection as well.

    – Naman
    Mar 23 at 3:04













2












2








2


1






I have a String problem for the Java 8 streams. They want me to change all the first letter into uppercase letter just if the words aren't into "the", "a", "to", "of", "in" group.



My problem is that the filter command does delete the words from the group and I have to keep them.



I have already done the part for the upper case first letter but I have no idea how to make the "jump" over the group of words



private List<String> ignoredWords = Arrays.asList("the", "a", "to", "of", "in");
String entryParts[] = toTitlelize.split(" ");

List<String> sentenceParts = Arrays.asList(entryParts);
List<String> finalSentence = sentenceParts.stream()
.map(WordUtils::capitalize)
.collect(toList());


For example :



if toTitlelize = "I love to eat pizza in my home"


It should return




"I Love to Eat Pizza in My Home"




for the moment it gives me:




"I Love To Eat Pizza in My Home"











share|improve this question
















I have a String problem for the Java 8 streams. They want me to change all the first letter into uppercase letter just if the words aren't into "the", "a", "to", "of", "in" group.



My problem is that the filter command does delete the words from the group and I have to keep them.



I have already done the part for the upper case first letter but I have no idea how to make the "jump" over the group of words



private List<String> ignoredWords = Arrays.asList("the", "a", "to", "of", "in");
String entryParts[] = toTitlelize.split(" ");

List<String> sentenceParts = Arrays.asList(entryParts);
List<String> finalSentence = sentenceParts.stream()
.map(WordUtils::capitalize)
.collect(toList());


For example :



if toTitlelize = "I love to eat pizza in my home"


It should return




"I Love to Eat Pizza in My Home"




for the moment it gives me:




"I Love To Eat Pizza in My Home"








java filter java-stream






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 1:25









Carlos Cavero

1,90841023




1,90841023










asked Mar 22 at 22:59









Artene Dragoş AndreiArtene Dragoş Andrei

133




133







  • 1





    You can choose to implement capitalize in such a way that it ignores the words from ignoredWords collection as well.

    – Naman
    Mar 23 at 3:04












  • 1





    You can choose to implement capitalize in such a way that it ignores the words from ignoredWords collection as well.

    – Naman
    Mar 23 at 3:04







1




1





You can choose to implement capitalize in such a way that it ignores the words from ignoredWords collection as well.

– Naman
Mar 23 at 3:04





You can choose to implement capitalize in such a way that it ignores the words from ignoredWords collection as well.

– Naman
Mar 23 at 3:04












1 Answer
1






active

oldest

votes


















2














You can use a simple if statement in you mapping step:



List<String> finalSentence = Arrays.stream(entryParts)
.map(word ->
if (ignoredWords.contains(word))
return word;

return WordUtils.capitalize(word);
)
.collect(Collectors.toList());


As an alternative you can use filter() and findFirst() on the ignoredWords and use an Optional:



List<String> finalSentence = Arrays.stream(entryParts)
.map(word -> ignoredWords.stream().filter(w -> w.equals(word)).findFirst().orElse(WordUtils.capitalize(word)))
.collect(Collectors.toList());


I also would recommend to use a HashSet instead of a List, because the words are unique and contains() is much faster:



HashSet<String> ignoredWords = new HashSet<>(Arrays.asList("the", "a", "to", "of", "in"));


The result of String.join(" ", finalSentence); will be:




I Love to Eat Pizza in My Home







share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55308831%2fi-need-to-do-changes-just-on-specific-words%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    You can use a simple if statement in you mapping step:



    List<String> finalSentence = Arrays.stream(entryParts)
    .map(word ->
    if (ignoredWords.contains(word))
    return word;

    return WordUtils.capitalize(word);
    )
    .collect(Collectors.toList());


    As an alternative you can use filter() and findFirst() on the ignoredWords and use an Optional:



    List<String> finalSentence = Arrays.stream(entryParts)
    .map(word -> ignoredWords.stream().filter(w -> w.equals(word)).findFirst().orElse(WordUtils.capitalize(word)))
    .collect(Collectors.toList());


    I also would recommend to use a HashSet instead of a List, because the words are unique and contains() is much faster:



    HashSet<String> ignoredWords = new HashSet<>(Arrays.asList("the", "a", "to", "of", "in"));


    The result of String.join(" ", finalSentence); will be:




    I Love to Eat Pizza in My Home







    share|improve this answer



























      2














      You can use a simple if statement in you mapping step:



      List<String> finalSentence = Arrays.stream(entryParts)
      .map(word ->
      if (ignoredWords.contains(word))
      return word;

      return WordUtils.capitalize(word);
      )
      .collect(Collectors.toList());


      As an alternative you can use filter() and findFirst() on the ignoredWords and use an Optional:



      List<String> finalSentence = Arrays.stream(entryParts)
      .map(word -> ignoredWords.stream().filter(w -> w.equals(word)).findFirst().orElse(WordUtils.capitalize(word)))
      .collect(Collectors.toList());


      I also would recommend to use a HashSet instead of a List, because the words are unique and contains() is much faster:



      HashSet<String> ignoredWords = new HashSet<>(Arrays.asList("the", "a", "to", "of", "in"));


      The result of String.join(" ", finalSentence); will be:




      I Love to Eat Pizza in My Home







      share|improve this answer

























        2












        2








        2







        You can use a simple if statement in you mapping step:



        List<String> finalSentence = Arrays.stream(entryParts)
        .map(word ->
        if (ignoredWords.contains(word))
        return word;

        return WordUtils.capitalize(word);
        )
        .collect(Collectors.toList());


        As an alternative you can use filter() and findFirst() on the ignoredWords and use an Optional:



        List<String> finalSentence = Arrays.stream(entryParts)
        .map(word -> ignoredWords.stream().filter(w -> w.equals(word)).findFirst().orElse(WordUtils.capitalize(word)))
        .collect(Collectors.toList());


        I also would recommend to use a HashSet instead of a List, because the words are unique and contains() is much faster:



        HashSet<String> ignoredWords = new HashSet<>(Arrays.asList("the", "a", "to", "of", "in"));


        The result of String.join(" ", finalSentence); will be:




        I Love to Eat Pizza in My Home







        share|improve this answer













        You can use a simple if statement in you mapping step:



        List<String> finalSentence = Arrays.stream(entryParts)
        .map(word ->
        if (ignoredWords.contains(word))
        return word;

        return WordUtils.capitalize(word);
        )
        .collect(Collectors.toList());


        As an alternative you can use filter() and findFirst() on the ignoredWords and use an Optional:



        List<String> finalSentence = Arrays.stream(entryParts)
        .map(word -> ignoredWords.stream().filter(w -> w.equals(word)).findFirst().orElse(WordUtils.capitalize(word)))
        .collect(Collectors.toList());


        I also would recommend to use a HashSet instead of a List, because the words are unique and contains() is much faster:



        HashSet<String> ignoredWords = new HashSet<>(Arrays.asList("the", "a", "to", "of", "in"));


        The result of String.join(" ", finalSentence); will be:




        I Love to Eat Pizza in My Home








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 23 at 0:06









        Samuel PhilippSamuel Philipp

        4,66431531




        4,66431531





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55308831%2fi-need-to-do-changes-just-on-specific-words%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript