Here is is my problem, I have to explain a lot, because it’s a quite complicated. I have created an arrayList<Word>, that contains strings as objects. In my case, I have three classes, all working together, that is supposed to represent a dictionary. The first class is called “Word”, it has a constructor, and has simple methodes like .length, adds
Tag: string
Java text wrap issue, caused by input width
I am trying to wrap text based on a width of 10 characters. After looking at other questions, I have the following: This works until a word in my string is longer than the specified width. When this occurs, the rest of the string is printed on line line instead of still following the line width rule. Any ideas? I
indexOf to find all occurrences of a word in a String
I’m trying to use indexOf to find all occurrences of the characters ‘the’ in a sentence. For example, if the sentence were “The other day I went over there”, it should return 3. I am able to do this …
Replace Unicode escapes with the corresponding character
I’m trying to convert code points, such as u00FC, to the character it represents. An example to explain what I mean: First Console line: Input: Hallu00F6 Second Console line: And Now: Hallö EDIT: Because sometimes it didn’t work with multiple Unicodes in The Trombone Willy’s answer, here is the Code fixed: Answer Joao’s answer is probably the simplest, but this
Better way to replace unnecessary scan.nextLine(); to find StdIn String?
I’ve been working through the HackerRank problems and trying to always research a solution before asking in any communities for help. While I managed to get the current one to work, I feel there is some unnecessary code involved and that someone can teach me how to do it better, as I’d hate to pick up a bad habit just
How can i put a string in one line
i’m doing some conversion, from Hex to Ascii, when i convert the string, i got the following example: F23C040100C1 100D200000000000 0000 I know that the string is coming like this, because of the base 16, but i want too put it in just one line, like this: F23C040100C1100D2000000000000000 How can i do that? I have tried: Answer There are multiple
Unique regex for first name and last name
I have a single input where users should enter name and surname. The problem is i need to use checking regEx. There’s a list of a requirements: The name should start from Capital Letter (not space) There can’t be space stacks It’s obligate to support these Name and Surname (all people are able to write theirs first/name). Example: And the
Java .split(“|”) not working
I just ran into the problem that the split method for strings wouldn’t work with character “|” as an argument. It somehow separates each character in the string. Code: Output: Answer Use escape character before | like below: Similar “escape character logic” is required, when you are dealing/splitting with any of the below special characters (used by Regular Expression): OR
How to calculate a length of array with out using library
yesterday I appeared in interview,interviewer told me to write a code for calculating a length of array with out using a length property of Array class. For examaple- All answer given here are using String library. Answer
How many objects are created in StringBuilder?
Based on my understanding on String objects, that every string literal is being added/created on the String Constant Pool. two objects are being created, one is the “hello world” being added on the constant pool and the other object is the new instance of String. Does the same principle is being applied when it comes to StringBuilder? in the StringBuilder