@@ -10,22 +10,17 @@ import java.util.*; // Importing utility classes for List and Arrays
10
10
import java.util.stream.IntStream ; // Importing IntStream for range and mapping
11
11
import java.util.stream.Collectors ; // Importing Collectors for collecting stream results
12
12
13
- public class Main {
14
- // Generic method to zip two lists into a list of paired elements
15
- public static <A , B > List<List<Object > > zip (List<A > list1 , List<B > list2 ) {
16
- // Create pairs by iterating through the indices of both lists
17
- return IntStream . range(0 , Math . min(list1. size(), list2. size())) // Limit the range to the smaller list
18
- .mapToObj(i - > Arrays . asList(list1. get(i), list2. get(i))) // Pair elements from both lists at index i
19
- .collect(Collectors . toList()); // Collect the pairs into a List
20
- }
13
+ public < A , B > List<List<Object > > zip(List<A > list1, List<B > list2) {
14
+ // Create pairs by iterating through the indices of both lists
15
+ return IntStream . range(0 , Math . min(list1. size(), list2. size())) // Limit the range to the smaller list
16
+ .mapToObj(i - > Arrays . asList(list1. get(i), list2. get(i))) // Pair elements from both lists at index i
17
+ .collect(Collectors . toList()); // Collect the pairs into a List
18
+ }
21
19
22
- public static void main (String [] args ) {
23
- // Usage:
24
- List<String > arr1 = Arrays . asList(" a" , " b" , " c" );
25
- List<Integer > arr2 = Arrays . asList(1 , 2 , 3 );
26
- List<List<Object > > zipped = zip(arr1, arr2);
20
+ // Usage:
21
+ List<String > arr1 = Arrays . asList(" a" , " b" , " c" );
22
+ List<Integer > arr2 = Arrays . asList(1 , 2 , 3 );
23
+ List<List<Object > > zipped = zip(arr1, arr2);
27
24
28
- System . out. println(zipped); // Output: [[a, 1], [b, 2], [c, 3]]
29
- }
30
- }
25
+ System . out. println(zipped); // Output: [[a, 1], [b, 2], [c, 3]]
31
26
```
0 commit comments