SHARE
TWEET

zip arrays

DulcetAirman Jun 21st, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ch.claude_martin;
  2.  
  3. import java.util.stream.IntStream;
  4.  
  5. public final class SomeClass {
  6.   private static final String FORMAT = "%s, %d, %s%n";
  7.  
  8.   public static void main(String[] args) {
  9.     String[] names = { "Alice", "Bob", "Oscar" };
  10.     int[] ages = { 35, 65, 23 };
  11.     String[] gender = { "Cis Female", "Cis Male", "Other" };
  12.  
  13.     assert names.length == ages.length && names.length == gender.length;
  14.  
  15.     for (int i = 0; i < names.length; i++) {
  16.       System.out.format(FORMAT, names[i], ages[i], gender[i]);
  17.     }
  18.     System.out.println("---");
  19.  
  20.     IntStream.range(0, names.length).mapToObj(i -> String.format(FORMAT, names[i], ages[i], gender[i]))
  21.         .forEach(System.out::print);
  22.  
  23.   }
  24.  
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top