Campbell Ritchie wrote:Can you have a sensible result from toString() on a Stream? A Stream is an Object, so you can use the un‑overridden version of toString, but how are you going to print its contents? A Stream does not “have” any contents...
They are not so much produced as come from somewhere else, e.g. a List, or the preceding Stream. They don't so much exist in the Stream as run along it, so how are you going to catch them?
Winston Gutkowski wrote:. . . Sure it does; it has elements. I just don't care how, where or when they're produced, providing they ARE produced when I use it. . . .
Campbell Ritchie wrote:Yes, a CharSequence#charStream method would probably have been useful. And a CharStream class. But if it is so easy to write
mapToObj(i -> Character.valueOf((char)i)
I don't think it is going to happen.
Knute Snortum wrote:Welcome to the Ranch!
What happens if you try this in your main method?
Some other thoughts: what happens when you make two calls to clean_string in main?
The Java convention for naming with multiple "words" is ThisIsAClassName and thisIsAMethodName. That is, camel case with classes starting with an uppercase letter and methods starting with a lowercase letter, no underscores.
Knute Snortum wrote:In general -- and especially when you are a beginning programmer -- the use of a static variable is a sign that something is wrong with the design. Can you think of a way to not use a static variable?
Ranajoy Saha wrote:Hi, Everyone
Here's the question
Given a string, return recursively a "cleaned" string where adjacent chars that are the same have been reduced to a single char. So "yyzzza" yields "yza".
stringClean("yyzzza") → "yza"
stringClean("abbbcdd") → "abcd"
stringClean("Hello") → "Helo"
The iterative approach would be this.
The signature that I must stick to is public String stringClean(String str) and have to solve it without using replace() or replaceWith(). How should I approach writing my program now?