How to sort and cut String in Java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to sort and cut String in Java

Hello there! I am developing a software that takes the content of a text file and draws the text onto the screen with automatically generated colored ovals behind groups of text to increase reading speed. I have a separate class called "cutter()" and behaves as follows: The method takes in a string (the contents of the text file) and returns an ArrayList of type String. The algorithm within should be able to locate when to end the line after finding the last space before hitting the character limit. For example: private ArrayList cutter(String fileContent) { Variables: character limit per line (the amount of characters a single line of drawn string can have up to), the arraylist this method returns, and the localized public instance String scanned in another method. Algorithm pseudo: Scan through the text and locate the last space (" ") before hitting the character limit. Once finding this segment, deleting the last space and adding it to the ArrayList. Continuing until the entire String has been snipped. } Algorithms and substrings have always been my weakness. If you can offer any insight regarding my obstacle here, that would be greatly appreciated. Thank you for your consideration!

2nd Dec 2020, 1:46 PM
Fleet
Fleet - avatar
2 Answers
+ 12
Hii Fleet I guess you are asking to "cut java string at a number of character"? So if it's that then might this will be useful resource for you https://stackoverflow.com/questions/17685977/cut-java-string-at-a-number-of-character Hope this will give a little help✌️
2nd Dec 2020, 2:59 PM
Piyush
Piyush - avatar
+ 2
That works beautifully. Thank you for your help!
3rd Dec 2020, 4:26 PM
Fleet
Fleet - avatar