Your Computer Science Resource

Posts Tagged ‘wrap’

Oct
27th

HOW-TO: Wrap Strings in Java

Ever wonder why there’s no method to wrap a String based on a certain number of characters? Me, too. Having the ability to wrap Strings can be especially useful if you don’t know how long your Strings are going to be, such as when you have translated text in a JOptionPane (or any other GUI element). Unfortunately, there is no built-in function to do this within the String class. But of course, we can write a nice utility class that does exactly what we need — StringWrapper.

(more…)