Advertisement
DulcetAirman

array of BitSet

Jun 1st, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. package ch.claude_martin.playground;
  2.  
  3. import java.io.IOException;
  4. import java.nio.charset.StandardCharsets;
  5. import java.nio.file.Files;
  6. import java.nio.file.Paths;
  7. import java.util.BitSet;
  8. import java.util.List;
  9. import java.util.stream.Collectors;
  10.  
  11. public class SomeClass {
  12.  
  13.     public static void main(String[] args) throws IOException {
  14.         String path = "matrix.txt";
  15.         List<BitSet> matrix = Files.lines(Paths.get(path), StandardCharsets.US_ASCII).map(l -> parseLine(l))
  16.                 .collect(Collectors.toList());
  17.         // ...
  18.     }
  19.  
  20.     static BitSet parseLine(String line) {
  21.         String[] a = line.split("\\s+");
  22.         final BitSet bs = new BitSet(a.length);
  23.         for (int i = 0; i < a.length; i++) {
  24.             if (Integer.parseInt(a[i]) == 1)
  25.                 bs.set(i);
  26.         }
  27.         return bs;
  28.     }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement