How can I split file by newline? I’ve attempted to split by doing line.split(“\r?\n”) – but when I try printing the 0th index I get the entire file content when I was expecting just the first line. but if I try printing the result at index 0 I get the entire file content, when I expected to get just the
Tag: string
How do you check if a word has an anagram that is a palindrome?
How do you compare a palindromic word to one of the newly formed words of an anagram? And how do you grab one of the newly formed words for it to be compared to the input word? This is my code: It’s not yet done because the permutation and comparison won’t work. The output is displaying false, I need it
Condition to point out Error in line formatting not being met
I have a program which reads a file and enforces a certain format in every line. If a line has a format error, it prints a line below it indicating which error it was. For each line, From column 1 to …
How can I get a special part in a string in Java? [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago. Improve this question I have to read commands from a file I have and take necessary actions according to each command. I was able to find out the
Remove every space EXCEPT leading spaces
I need to remove every spaces from a String EXCEPT leading spaces. I have some strings that look like this : And I am trying to achieve this : That’s like a reverse trim(). What’s the most efficient way to go about it ? Answer You can use replaceAll with this regex (?<=S)(s+)(?=S) like this : Examples of input &
Converting String number words to just String number:Java
I’m a beginner coder trying to work on converter for words which should work that way:Input= “zero;six;eight;two” Output = “0682”. But in my case the output I get is “0282”. Are there any solutions to that? Or like maybe I should program differently?. I found that LinkedLists or HashMap could work, if so could you show how? Answer You should
How to best determine whether the date format is MM/dd or DD/mm in java
I have list of files coming and I need to analyze them using java. The date field is read from files as String and I need to parse it in to LocalDatTime. The problem is it is now known that whether the first part of date is month or day. The format in them can be anything but most probably
Is there a way for a program to create a new int dynamically?
Is there a way to have a program generate a random string and then create an int using that string? I need an indefinite number of int, so I can’t exactly define them all in the code and then write in …
How do I get the Scanner in java to read a string? [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago. Improve this question How would I get my program to quit when the user enters q? Is there something wrong with the scanner?
How to skip a leading string when scanning text file?
I’m making a program that draws a basic image using instructions from a text file. The format for the instructions is: and this is my code: this is giving a NoSuchElementException. I’m assuming it’s because the fwidth and fheight are taking the leading strings as ints but i can’t figure out how to get the scanner to skip the strings