I was reading Android documentation regarding Shared Preferences here And they have mentioned one thing,
You can use SharedPreferences to save any primitive data: booleans, floats, ints, longs, and strings.
To best of my knowledge there are 8 primitive types in Java ie. byte, char, short, int, long, float, double, boolean
String is a class in Java under java.lang package, not a primitive type.
So questions arise,
Q1. Why this thing is written in Android documentation that Primitive data: string?
Q2. Does this primitive word used here, mean something else than the primitive data type?
Thanks.
You're correct that strings are not a primitive data type in Java:
In addition to the eight primitive data types listed above, the Java programming language also provides special support for character strings via the
java.lang.String
class.Enclosing your character string within double quotes will automatically create a new
String
object; for example,String s = "this is a string";
.The
String
class is not technically a primitive data type, but considering the special support given to it by the language, you'll probably tend to think of it as such.
However, it may be that, in this context, "primitive" refers not to the Java primitive types but to a scale from simple to complex.
That page you reference has, in the "storage quick view", the following points:
That seems to run the scale from simple to complex (primitive, large and structured).
Or it may be that Android just follows the text mentioned in the Java tutorials (see above) and treats strings as a primitive type, despite the fact it's not technically the case.
You know, the same way we claim Java is object-oriented despite the fact that Python/Ruby/Smalltalk fans will argue that the presence of primitive types makes that claim false, right up until the point until your ears drop off to protect your sanity :-)
In any case, I'm not sure it matters. Android is specified by the Android documentation primarily, with Java documentation as fallback (as you can see by their differing approaches to internationalisation). It was meant to leverage the Java skills out there rather than provide the exact same environment.
If the Android documentation refers to strings as primitive, it considers them primitive, at least in terms of what you can use for shared preferences.