
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Ways to Create a String Object in Java
You can create a String by −
Step 1 − Assigning a string value wrapped in " " to a String type variable.
String message = "Hello Welcome to Tutorialspoint";
Step 2 − Creating an object of the String class using the new keyword by passing the string value as a parameter of its constructor.
String message = new String ("Hello Welcome to Tutorialspoint");
Step 3 − Passing a character array to the String constructor.
char arr[] = {'H','e','l','l','o'}; String message = new String(arr);
Advertisements