| Author |
difference between java Streams and strings
|
Bhasker Reddy
Ranch Hand
Joined: Jun 13, 2000
Posts: 176
|
|
What is the exact difference between java Streams and Java STrings. Can someone advise me.
|
Bhasker Reddy
|
 |
Rob Ross
Bartender
Joined: Jan 07, 2002
Posts: 2205
|
|
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
|
Rob
SCJP 1.4
|
 |
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
|
|
|
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.
|
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
|
 |
Bhasker Reddy
Ranch Hand
Joined: Jun 13, 2000
Posts: 176
|
|
|
Thanks guys for your info
|
 |
Rob Ross
Bartender
Joined: Jan 07, 2002
Posts: 2205
|
|
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
Joined: Aug 26, 2001
Posts: 7610
|
|
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
|
SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
|
 |
 |
|
|
subject: difference between java Streams and strings
|
|
|