X hits on this document

162 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 views162
Page views162
Page last viewedSun Jan 22 16:58:48 UTC 2017
Pages46
Paragraphs816
Words2901

Comments