Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8781525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:19:34+00:00 2026-06-13T20:19:34+00:00

I am new to java and trying to understand the essentials and fundamentals of

  • 0

I am new to java and trying to understand the essentials and fundamentals of the language.

Is it accurate to state that Java string objects are intrinsically a class defined as an immutable array of chars?

I ask this as I’m a bit confused by the spec in comparison to char arrays and the string class…

JLS 10.9

10.9 An Array of Characters is Not a String
In the Java programming language, unlike C, an array of char is not a String,
and neither a String nor an array of char is terminated by ‘\u0000’ (the NUL
character).
A String object is immutable, that is, its contents never change, while an array of
char has mutable elements.
The method toCharArray in class String returns an array of characters containing
the same character sequence as a String. The class StringBuffer implements useful
methods on mutable arrays of characters.

JLS 4.3.3

4.3.3 The Class String Instances of class String represent sequences of Unicode code points.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:19:35+00:00Added an answer on June 13, 2026 at 8:19 pm

    Is it accurate to state that Java string objects are intrinsically a class defined as an immutable array of chars?

    No. A Java String object is (currently – it’s an implementation detail which I gather may be changing) a class containing a few fields:

    • A char[] containing the actual characters
    • A starting index into the array
    • A length
    • A cached hash code, lazily computed

    The reason for the index and length is that several strings can contain references to the same char[]. This is used by some operations such as substring (in many implementations, anyway).

    The important thing is the API for String though – which is very different to the API for an array. It’s the API you would think of when you take the JLS definition into account: a String represents a sequence of Unicode code points. So you can take a subsequence (Substring), find a given subsequence (indexOf), convert it to an upper case sequence etc.

    In fact the JLS would be slightly more accurate to call it a sequence of UTF-16 code units; it’s entirely possible to construct a string which isn’t a valid sequence of Unicode code points, e.g. by including one half of a “surrogate pair” of UTF-16 code units but not the other. There are parts of the API which do deal with the String in terms of code units, but frankly most developers spend most of the time treating strings as if non-BMP characters didn’t exist.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm relatively new to Java and I'm still trying to understand the fundamentals. I
I am new to mutli-threading in java and trying to understand the keyword synchronization
I'm still new to programming/Java/Android so I'm trying to understand everything I do and
Hey I'm new to java servlets and I am trying to write one that
I am relatively new java. I am trying understand what are the usage of
I'm trying to understand how Java objects behave in a Domino environment and am
Trying to understand upcasting in Java. Recently observed strange behavior. Example: public class A
I'm new to Java and trying to understand how dictionary in compression works. public
I'm new to Android(and Java also) and I'm trying to understand what are Fields
Good morning I am learning Java and trying to understand the access to class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.