Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this lab, you will write a program that processes a file using Java stream processing. The file is a text file containing lines of
In this lab, you will write a program that processes a file using Java stream processing. The file is a text file containing lines of the form: 271.72296.3347.70231.61 That is, each line of the file contains four positive double values. Unfortunately, mistakes in the collection and production of the file are possible: their may be non-positive values in the file and the file may contain values that are not numeric. Step 1: Write a stream processing that produces a List from the file Input2.txt that contains only numeric, positive values. 1. Use the Files.lines() and Paths.get() to open and read the file to a stream. 2. Use the Stream.map() method to spit the lines into an array of four strings containing the values. 3. Use the Stream. filter() method to pass only arrays that only have strings that represent double values (use the String.matches ( method in the filter. 4. Use the Stream.map() method to convert each array of string into an array of Doubles. 5. Use the Stream. filter() method to pass only arrays that have all positive values. 6. Use the Steam.collect() method to collect the arrays into a list. The Collectors.toList() can do this. 7. After the stream has produced the list, display it. Use Arrays.toString() to display each array: List
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started