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;
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
add a comment |
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
1
You can choose to implementcapitalize
in such a way that it ignores the words fromignoredWords
collection as well.
– Naman
Mar 23 at 3:04
add a comment |
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
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
java filter java-stream
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 implementcapitalize
in such a way that it ignores the words fromignoredWords
collection as well.
– Naman
Mar 23 at 3:04
add a comment |
1
You can choose to implementcapitalize
in such a way that it ignores the words fromignoredWords
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
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Mar 23 at 0:06
Samuel PhilippSamuel Philipp
4,66431531
4,66431531
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
You can choose to implement
capitalize
in such a way that it ignores the words fromignoredWords
collection as well.– Naman
Mar 23 at 3:04