Return to Coding in Java with artEoz – exercises

String class

  1. The statements below instantiate strings as instances of java.lang.String class in various ways. Can you identify these ways?
  1. 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? key_48
  2. 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? key_48
    Why these objects became unreferenced? key_48
  3. Add the statement to create a new string containing the same characters as those in c4. key_48
  4. 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? key_48
  5. 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.

Back to java exercises list