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 ?
We can use the Integer. parseInt() to get the corresponding primitive int value of a string or use Integer. valueOf() to get the corresponding value of Integer wrapper class. If the string is not an integer, NumberFormatException will be thrown.
String is nothing but a sequence of characters. The String is a Class and not a data type like 'int & char'. So the String class represents the characters of String and all string objects in java are the instance of this class.
Class String. The String class represents character strings. All string literals in Java programs, such as "abc" , are implemented as instances of this class. Strings are constant; their values cannot be changed after they are created.
In the Java programming language, strings are objects. The Java platform provides the String class to create and manipulate strings.
No. String is not a wrapper class, simply because there is no parallel primitive type that it wraps.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With