Skip to content
Advertisement

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 (). Using regex, I suppose the group() method

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 containing

Casting a string to an integer and then to a double – how to retrieve up to four positions behind the decimal position in a correct way?

I am currently working on a simple BMI (Body Mass Index) calculator in Java, in a larger Java / Spring Boot application with Mojito Tests. My function uses height and weight as Input values to calculate the BMI. Through the arithmetic operations, the received Input values – Strings, casted to Integers – result in a number that represents the BMI;

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, CorePlatformRuntime, CorePlatformRuntimeConfiguration || DetailPageAlternative, DetailPageBooks, DetailBuild || HorizontePage, HorizontePageLogging, HorizonteBuild Explanation- Grouped based on Core, Detail, Horizonte Input : 2 Output: CorePlatformPortal, CorePlatformRuntime, CorePlatformRuntimeConfiguration || DetailPageAlternative, DetailPageBooks, HorizontePage, HorizontePageLogging

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 see, s.subString(0, 8) will return the above

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, here is my text file

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 visible here too): Any ideas welcome… what could I try? BTW: java 17 is allowed 🙂 The following code seemss to

Advertisement