Search code examples
javaandroidstringsharedpreferencesprimitive

Is String a primitive or an Object in Android or Java?


In the Android API http://developer.android.com/guide/topics/data/data-storage.html#pref

It says:

Shared Preference allows you to save and retrieve persistent key-value pairs of primitive data types. You can use SharedPreferences to save any primitive data: booleans, floats, ints, longs, and strings.

Is String a primitive data type or an Object?


Solution

  • As far as Java programming language is considered,

    A primitive type is predefined by the language and is named by a reserved keyword.

    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.

    —— from The Java™ Tutorials - Primitive Data Types

    So, as such in Java books, it's not a keyword and not a primitive either. SharedPreferences may still call it one of the primitives, but that's not from the book of Java as such, it could be because it's one of the set of basic types like int, float, char etc we come across.