Does Java have a StringStream equivalent?

So, I have been trying to return to Java after running C ++ for some time, I decided to practice rewriting my C ++ programs in Java. Now in my Min Max program, I have the following lines of code:

//C++ Code Sample getline(cin,mystr); stringstream(mystr) >> value; max = value; min = value; stringstream stream(mystr); while(stream >> value) { if(value > max) { max = value; } else if(value < min) { min = value; } } 

Now getline is equivalent to using the Scanner class, but what of StringStream? During the search, I saw people mentioning InputStream, but this seems to be related to reading from a file, for example: http://www.tutorialspoint.com/java/io/inputstream_read.htm .

So, I was wondering if I can get similar functionality? I could also ask the user to specify how much input they want to enter, and then just populate the array; but it seems uncomfortable.

Update:

I created a quick work that works as follows:

  String in = ""; while(true) { in = input.nextLine(); if(in.equalsIgnoreCase("DONE")) { break; } value = Integer.parseInt(in); if(value > max) { max = value; } else if(value < min) { min = value; } } 
+6
source share
1 answer

You can use java.util.Scanner to parse String using a scanner (String) . You can also use java.lang.StringBuilder to efficiently build strings.

+7
source

All Articles