Skip to content

Tag: string

Finding the longest word ArrayList /Java

I want to write a method which finds the longest String (word). The output should be the longest word in case of two words with the same lenght the output should be: “More than one longest word”. I used ArrayList and almost had a solution, but something goes wrong. The case is that I have a problem when two words

Java – Check if user input partialy matches another string?

I have a problem where i want to see if the input user has enterd partially matches, or as long as majority matches with the answer, if it does then it should print out “Almost correct”. For example lets say the answer is Football, but user instead puts in Footbol. It should then print out Almost correct. here is what

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

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

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

List of int array in Java

How do I print the contents of a List that contains a primitive type int object in it? Prefer answers to print this in one line. This is the code I have. This will give me [0,1] but I am looking for {[0,1],[2,3]} Answer The following one-liner can meet your requirement: It uses the positive lookbehind and positive lookahead regex

Substring a string in JAVA

Is possible to substring this String = “D:/test/for test/change.txt:D:/test/for test/further.txt:D:/test/for test/yandex.txt” to: Because are two column, I can not split() use “:”. Answer A simple regular expression below splits on “:” that are followed by a “driveletter:” Note that this won’t help if additional paths don’t begin with driveletter: