X hits on this document

104 views

0 shares

0 downloads

0 comments

45 / 46

© S. Uchitel, 2004

45

A comment on Strings

Strings are objects of class String...

You can create Strings as usual

String a = null;

String b = new String(); // Creates empty string

a = new String(“Hello!”); // Creates Hello! string

you can also create them without using “new”

String a = null;

String b = “”; // Creates empty string

a = “Hello!”; // Creates Hello! string

Besides, strings are immutable. (They have no methods for changing their value)

String a = new String(“You can’t change me!”);

f(a); /* Although f(String s) has a

reference to the object created

above, it will not be able to

change its value */

This is particularly relevant

for C++ programmers

Document info
Document views104
Page views104
Page last viewedMon Dec 05 13:15:18 UTC 2016
Pages46
Paragraphs816
Words2901

Comments