Special String Operations Java Help

Special String Operations 

Because strings are a common and important part of programming, Java has added special support for several string operations within the syntax of the language. These operations include the automatic creation of new 'String instances from string literals, concatenation of multiple String objects by us,e of the +operator, and the conversion of other data types to a string representation. There are explicit methods available to perform all of these functions, but Java' does them auto tidally as a convenience for the programmer and to add clarity

String Literals

The earlier examples showed how to explicitly create a String instance from an array of '. characters by using the new operator. However, there is an easier way to do this using a string literal. For each string literal program, java automatically constructs a String object. Thus, you can use a string literal to.initialize a String object; For example, the following code fragments two equivalent strings:' Because a String object is created for every string literal, you can use a string literal anyplace you can use a String object. For example, you Can call methods directly on a quoted string as if it were an object reference, as the following statement shows. It calls the Strength ) method on the string "abc". As expected, it prints.

Posted on September 17, 2014 in Staring Handling

Share the Story

About the Author

Back to Top
Share This