Sign up ×

Wrapper classes are used to "wrap" the primitives data types into objects so that they can be included in the activities which are reseved for the objects. String class wraps the string literals to an object.

In this scenario can we call String as a wrapper class ?

share|improve this question
I like to call String "Fred". No, I wouldn't call that a wrapper class. I don't know what it improves if I do. – duffymo Jul 6 '11 at 9:44
wrapper class implicitly refers to a PRIMITIVE wrapper class. so considering it's implicit definition, String is not a wrapper class. – mostafa.S Mar 8 at 13:43

6 Answers 6

up vote 6 down vote accepted

According to wikipedia, a (primitive) wrapper class in Java is one of those eight classes that wrap a (=one) primitive value. String wraps a char[] so according to this it is not a (primitive) wrapper class.

Furthermore, String is not designed to wrap or decorate a character array. String has been designed to model a string, a character sequence and the current implementation uses an internal char[]. But Sun could also have chosen to use a byte[] a long with a character encoding hint, a collection or something native. That doesn't matter.

That's different for the primitive wrappers: they have been designed only to wrap a primitive, to adapt a java primitive to java.lang.Object.

share|improve this answer


From wiki:

A primitive wrapper class in the Java programming language is one of eight classes provided in the java.lang package to provide object methods for the eight primitive types

share|improve this answer

A string is a representation of a char sequence but not necessarily a 'wrapper'. Autoboxing and unboxing for example do not apply to String. But they do apply to primitives such as int long etc.

share|improve this answer

No, a String doesn't wrap the literal value. A literal gives you a different way to create a String object. But the literal itself is an object, so you could do things like:

System.out.println("Hello world".toUpperCase());

Not that you would want to do this.

share|improve this answer

Conventionally no since it doesn't wrap one of the eight primitives, but I don't think it would hurt to call it this.

share|improve this answer

No we cannot call string as a wrapper class.Because sun people not included string in wrapper classes.

share|improve this answer
Is that answer useful? seeing all the other (and one accepted) – manuell Dec 27 '13 at 11:57

Your Answer


