io - Java 8 & NIO / Read lines -> collect to entity -
The text file needs to be read from the line and the Entity
for the values determined by the object
ID, name, weight 1, Mario, 80.2 2, Marco, 91.1 ... 100, Diego, 78.12
Using the new Java 8: My solution of the method is very much Huge:
public work CoolApp {private static final String source = FILE = "path / to / txt / file / entities.txt"; Private static last IID id = 0; Personal Static Last End NAME = 1; Personal stable final variable weight = 2; Public static zero master (string [] args throws an exception {boolean isHeader = true; & Lt; Unit & gt; Organizations = New Arrestist & lt; & Gt; (); (String line: files .readlined lines (path.jet (SORCIOIELE)) {if (header) {header = real; } And {string [] snippets = line split (","); Institutions.ed (new unit (integer PRIINT (snippets [ID]), snippet [NAME], double PRSDB (SPIGHT) [WEIGHT])); }}}}
How can I do the same thing, but as used in presenting the data in the collection of institutions as follows?
list & lt; Unit & gt; Entities = files.line (path. (SOURCE_FILE)). Assemble (...);
list & lt; Unit & gt; Organizations = Files.lines (paths.get (SOURCE_FILE)). Skip (1) // Header Line. Map (Line -> Line Split (",")) // Convert each row to an array. Map (Snippets - & gt; New unit (integer. PRIIT Snippets [id]), snippets [NAME], double. PRSW ([WEIGHT]) // Transform each array into one unit.Collect (collectors.list ());
< P> Note on your code: You should use true
and false
, Boolean.TRUE
instead and Ulian. FALSE
(which are examples of Boolean and not primitive boolean value).
Comments
Post a Comment