What Are Some Methods for Manipulating Strings in Java?


Quick Answer

Among the many String methods listed in the Java API, the manipulation methods are concat, format, replace, toLowerCase, toUpperCase and trim. One of these methods is static, but the rest return Strings. Those that are static simply need to be called on an existing String. Static methods, however, must be called in an expression setting the desired String equal to the String calling this method.

Continue Reading
Related Videos

Full Answer

The static method for manipulation is format. With a String "s," the method is called by typing "s.format();" with proper parameters in the parentheses. The parameters for format are a format String and the arguments from the format String.

The remaining methods are called with a String "s" by typing "s = s.method();" with proper parameters. The first of the remaining methods, concat, takes a String parameter and cuts off anything in the called String after that parameter. Next, replace takes one input for the string being replaced and another input (or an empty input) for what it will be replaced with. The toLowerCase and toUpperCase methods make all of the characters in the String lower and upper case respectively. Finally, the trim method removes any white space from the front and back of the String.

Learn more about Computer Programming

Related Questions