why strings in java when we can have array of characeter or viceversa?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • b laxmikanth
    New Member
    • Oct 2010
    • 2

    why strings in java when we can have array of characeter or viceversa?

    why strings in java when we can have array of characeter or viceversa?
  • Ciary
    Recognized Expert New Member
    • Apr 2009
    • 247

    #2
    because an array is fixed size, and a string isn't. a string is more an arraylist of chars but appending to an arraylist requires more code than appending 2 strings together.

    Comment

    • Hal p

      #3
      In Java Strings are immutable, so they technically are a fixed size. They are far more convenient and easier to use than Char[] though. Say you have String s = "hi". You can call any function on s, but as long as you don't break the reference to s you will always be able to see that s = "hi".

      Comment

      Working...