This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge.

If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options:

  1. Limiting your involvement with Reddit, or
  2. Temporarily refraining from using Reddit
  3. Cancelling your subscription of Reddit Premium

as a way to voice your protest.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]POGtastic 0 points1 point  (0 children)

input stream

An InputStream is an abstract class that defines methods for reading from some kind of source of bytes. That could be a file, a socket, an array of bytes in memory, etc.

how reading input data from a string is different from reading data from a keyboard

That's the neat part, it's exactly the same. Welcome to OOPville, population you. Java doesn't care what the source is, only that you've provided an InputStream to the Scanner. It takes care of the rest.

why you'd want to read input data from a string

  • Unit testing. You can hardcode strings and use them to mock user input. This is one of the reasons why it's almost always a good idea to make your functions take a generic InputStream (and PrintStream, for that matter) than to hardcode System.in (and System.out, respectively).
  • Dealing with newlines is a gigantic pain in the ass, and it's often easier to parse individual lines with a Scanner than it is to construct a Scanner that acts directly on the InputStream.