- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Is String a primitive data type or an object in Java?
String is not a primitive data type. Java.lang package provides the String class therefore, it is an object type. You can create a string variable directly like any other variables as −
String s = "myString";
(or)
By instantiating the string class using the new keyword as −
String s = new String("myString");
Example
import java.util.Scanner; public class StringExample { public static void main(String args[]){ Scanner sc = new Scanner(System.in); System.out.println("Enter a sting value:"); String str = sc.nextLine(); System.out.println(str.getClass()); } }
Output
Enter a sting value: hello class java.lang.String
- Related Articles
- Is an array a primitive type or an object in Java?
- Is array a primitive data type in Java?
- Convert double primitive type to a Double object in Java
- Convert short primitive type to Short object in Java
- Convert byte primitive type to Byte object in Java
- Java Program to convert a Primitive Type Value to a String
- What are primitive data type in C++?
- Prove that the interface for a primitive type is an empty array in Java
- Java Program to convert a string into a numeric primitive type using Integer.valueOf()
- Java primitive data types
- Get the name of a primitive type in Java
- What are primitive data types in Java?
- Passing primitive values while instantiating a parameterized type (generic) in Java?
- What are the default values of instance variables whether primitive or reference type in Java?
- Convert long primitive to Long object in Java

Advertisements