Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 259
Krishna Prasad Avatar asked Jan 23 '13 06:01

Krishna Prasad


People also ask

Is String primitive or object in Java?

The string data type is a non-primitive data type but it is predefined in java, some people also call it a special ninth primitive data type. This solves the case where a char cannot store multiple characters, a string data type is used to store the sequence of characters.

Is String an object in Java?

Strings, which are widely used in Java programming, are a sequence of characters. In the Java programming language, strings are objects. The Java platform provides the String class to create and manipulate strings.

Is String a class or primitive in Java?

Primitive data types - includes byte , short , int , long , float , double , boolean and char. Non-primitive data types - such as String , Arrays and Classes (you will learn more about these in a later chapter)

Is String a primitive variable in Java?

Primitive types are the basic types of data: byte , short , int , long , float , double , boolean , char . Primitive variables store primitive values. Reference types are any instantiable class as well as arrays: String , Scanner , Random , Die , int[] , String[] , etc.


1 Answers

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.

like image 76
Swapnil Avatar answered Oct 05 '22 07:10

Swapnil