Skip to content

Tag: string

How to replace all substrings?

I want to replace all the text within brackets to uppercase letters for any String object. For example if the text is – Hi (abc), how (a)re (You)?” , output should be – Hi ABC, how Are YOU? . I tried to use StringUtils.SubstringBetween(), but that replaces only the first substring between ()…

Stack in Java not being able to print in specific order

Currently I’m working on a project that is supposed to be a reverse word guessing game. This is how it should work: The use keeps guessing the word until it is fully spelled out. If the user guesses the letter correctly it is revealed if not it is still reveled as shown below ⚠️ Currently I have a stack…

Group java string based on nth word in Camel case

I want to group certain java strings into subset of strings with same nth word. Eg List: CorePlatformPortal, CorePlatformRuntime, CorePlatformRuntimeConfiguration, DetailPageAlternative, DetailPageBooks, DetailBuild, HorizontePage, HorizontePageLogging, HorizonteBuild, Input : 1 Output: CorePlatformPortal, Co…

Why String index out of range?

below is my code for Leetcode 9 Palindrome Number. It shows “String index out of range error” for line 8 when the testcase is 121. Can anyone tell me why this happened? Thanks! Answer In the while loop, j remains constant whereas your “s” is reducing 1 char each loop. Example: as you s…

Adding a String into a scanner

//I wanted to insert a decimal number to console (like 1.85) to the String groesse and I also wanted it to be in the equation of bmi. How do i do that? } Answer How do i do that? OK, so you want to read user input from the console. To do so, instead of … use The same applies

Java .split method returning empty array

I am trying to count all the words in each sentence in an array of multiple sentences automatically from a file in eclipse. When I’m splitting the paragraph into sentences the java .split method is returning an empty array Here is the code that is causing me trouble here is my sentence class And finally…

How to simplify String concat in java?

Given the following code: I am trying and discussing in the team how the simpliest code could look like while one could use also constructs like: org.apache.commons.lang3.StringUtils: defaultString() MoreObjects.firstNonNull(user.getVorname(), Strings.EMPTY) A possible test could be like (expected results are…