With an Integer object I can do this:
Integer one = new Integer(3);
int oneval = one.intValue();
Is there something similar for the String object?
There is no primitive string type in Java. The closest you can get is to call toCharArray to get the char[] array of characters in the string (and it's a copy of the characters).
Returns:
a newly allocated character array whose length is the length of this string and whose contents are initialized to contain the character sequence represented by this string.
string type), since String is immutable. (Of course, so is Integer...)Strings are not primitives in Java. Every String is an object.
What you can get from a String is a character array, or an encoded byte array. Although these aren't primitives, they're at least arrays of primitives.
String s = "Twas brillig";
char[] sChars = s.toCharArray();
byte[] sBytes = s.getBytes(); // Default charset
byte[] sBytes = s.getBytes( Charset.forName("UTF-8") ); // Specific charset
Integeris the wrapper for anint, there is no primitiveString.Stringas similar.