This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

difference between java Streams and strings  RSS feed

 
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.
 
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
 
Sheriff
Posts: 9087
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
 
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
Boost this thread!