lines().collect(Collectors.joining("\n")) String result = new BufferedReader(new InputStreamReader(inputStream)) Warning: This solution converts different line breaks (like \r\n) to \n. String result = s.hasNext() ? s.next() : "" Using Scanner (JDK) Scanner s = new Scanner(inputStream).useDelimiter("\\A") Using CharStreams (Guava) String result = CharStreams.toString(new InputStreamReader( Using IOUtils.toString (Apache Utils) String result = IOUtils.toString(inputStream, StandardCharsets.UTF_8) Ways to convert an InputStream to a String: And I wrote some performance tests (see results below): Summarize other answers I found 11 main ways to do this (see below). The results of the method call are displayed in a dialog.Ĭlick the Inspect button to view the contents of the int array returned from your method, or click the Get button to add it to the object bench. Select the boolean add(Integer) method a few times to add some values to the instance.įinally, when you right click on your test class and call the toArray method, you can enter the name of the ArrayList instance to pass it as the argument to your method. When you right click on the new instance, BlueJ will display a menu of methods that can be called on it. Enter a name and Integer for the type parameter.Īfter you click Ok, the new ArrayList instance will appear in the object bench area at the bottom of the main BlueJ window. Also select the no-argument constructor from the list that appears, then click Ok.īlueJ will then display another dialog asking you for a name for the instance and for a type parameter for the ArrayList. With your project open in the main BlueJ window, click on the Tools menu, then on "Use Library Class.", then select from the Class menu. You need to create an instance of ArrayList to pass to your method when you call it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |