Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference between java Streams and strings

 
Bhasker Reddy
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the exact difference between java Streams
and Java STrings.
Can someone advise me.
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strings are arrays of characters used to hold data like "Hi I am a string."
A Stream is an i/o class that is used to read and write bytes of data as a continuous sequence of bytes. You can use streams to read and write data from/to files, among other things.
Rob
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A String is not an array of characters per the JLS. However, a String is a sequence of characters. JLS 4.3.3. A String is immutable. The elements of an array can be changed.
 
Bhasker Reddy
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys for your info
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mariyln,
it's always difficult to know how much detail to use when answering a question, so I tried to keep the answers simple.
You're right that an array of characters is not a string, but that's not what I said.
I said "a string is an array of characters."
From an implementation standpoint, this is correct. Look at the string class...

/** The value is used for character storage. */
private char value[];
Internally it keeps its data in an array of char.
So my statement is technically correct, even though there are significant differences between a String and a char array.
Rob
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob,
Marilyn is correct a String is not an array of character and an array of character is not a String either. The reason why the character array in class String is made private is that Sun wants the class to be the sole responsible of what happens to it, that is nothing since a String is immutable. Don't see a String as an array of characters or the opposite or else you may get into trouble. An array is mutable while a String is not...
I know that you know that but it is very important that things stay crystal-clear around here...
Also, you were wondering about the level of details in answers. Well, There are never enough details in my opinion... But one thing no one should do is use bad wording to keep it short, that's baaaaaaaad !! use proper wording even if it takes longer to explain.... Saying that a String is an array of character is a bad shortcut...
I'm picky I know Whatever
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic