- The statements below instantiate strings as instances of java.lang.String class in various ways. Can you identify these ways?
- The Simplified String display option of the Options menu allow to simplify (or not) the visualization of the objects of the String class. The exact representation (not simplified) of a string shows three fields: the first of them is the address of a contiguous area in which are stored the characters. We prefer the display of a simplified view of the memory because these 3 fields do not add much information. Do you have an idea of the other two fields store?
- The Unreferenced objects option of the Options menu may be use to understand the specific effect of each statement and to show exactly when an instantiation is done. An unreferenced object is an object, earlier created, but with no more reference from a variable or from an attribut class. These unreferenced objects are shaded. What are they here?
Why these objects became unreferenced? - Add the statement to create a new string containing the same characters as those in c4.
- Help yourself with the String documentation and write some functions calls on the String variables. Nothing that yoy can write will be able to modify the String instances (try to change/add/delete some characters). Do you know how we call these instances?
- If you wish to modify a string, the String class is not appropriate. You have to use the StringBuilder class. See the specific webpage StringBuilder.