Linked Questions
15 questions linked to/from How to zip two Java Lists
0 votes
1 answer
2k views
How to join 2 lists in Java-8 such that element at same indexes from the 2 list come together in the resultant list [duplicate]
I have 2 lists codeList and nameList both having String elements. codeList = ["1", "2", "3"]; nameList = ["One", "Two", "Three"]; I ...
0 votes
1 answer
670 views
Trying to create a 2 dimensional array from two existing arrays [duplicate]
I am very new to java and I am currently trying to recreate some python code in java. This is my problem: I have 2 different variables: ArrayList <Double> x_loc= new ArrayList<>(); ...
-1 votes
2 answers
485 views
How to convert two lists into list of objects [duplicate]
I have a class public class Person{ private String name; private Integer age; } And i also have two lists: List<String> names = List.of("Mike", "Piter", "Jack&...
-2 votes
1 answer
42 views
How the two list traversal output [duplicate]
List<String> list1=new ArrayList<String>(); list1.add("1"); list1.add("2"); list1.add("3"); list1.add("4"); List<String> list2=new ArrayList<String>(); ...
173 votes
14 answers
116k views
Zipping streams using JDK8 with lambda (java.util.stream.Streams.zip)
In JDK 8 with lambda b93 there was a class java.util.stream.Streams.zip in b93 which could be used to zip streams (this is illustrated in the tutorial Exploring Java8 Lambdas. Part 1 by Dhananjay Nene)...
50 votes
5 answers
29k views
What is zip (functional programming?)
I recently saw some Clojure or Scala (sorry I'm not familiar with them) and they did zip on a list or something like that. What is zip and where did it come from ?
24 votes
6 answers
21k views
Google Guava "zip" two lists
Using Google Guava (Google Commons), is there a way to merge two equally sized lists into one list, with the new list containing composite objects of the two input lists? Example: public class ...
4 votes
2 answers
19k views
Concatenate Vectors in Java
Is there any easy and quick way to merge 2 java vectors to 1? For example if I have: Vector<Object> Va = (Vector<Object>)Return_Vector_with_Objs(); Vector<Object> Vb = (Vector&...
3 votes
4 answers
2k views
new Java List of objects by matching entries in two other lists
suppose I have these two lists List<Person> persons = Arrays.asList( new Person(1, "Mike", "Canada"), new Person(2, "Jill", "England"), new ...
0 votes
2 answers
1k views
Java streams (forEach) to take attributes from one list and apply to another
I have a simple class: public class Thing { Long id; String color; String size; } I have two List<Thing> objects that looks like this: List<Thing> colors = [{2, red}, {3, blue}]; ...
0 votes
1 answer
893 views
How to enumerate (add indices) to a List-like collection in Java [duplicate]
Note: I am not referring to the java enum/enumeration but rather how to associate the ordinal/index of each element in a collection with the element. I am looking for the equivalent of : scala : (1 ...
2 votes
2 answers
776 views
zip method in java
Is there any equivalent of zip method from pyton in java? a = ("John", "Charles", "Mike") b = ("Jenny", "Christy", "Monica") x = zip(a, b) ...
1 vote
2 answers
828 views
Iterate and validate two lists of Objects in java 8
I have 2 lists: List1: Object1 (Empno1, Empname1,Salary1) List2: Object2(Empno2, Empname2,Salary2) Object3(Empno3, Empname3,Salary3) Given the size of List1 is not same as List2. I want to iterate ...
0 votes
1 answer
159 views
Accessing values inside ArrayList individually in JSP
In my servlet I have the following. All four are ArrayList<>, each with 5 values. request.setAttribute("interestEarnList", interestEarnList); request.setAttribute("numYear", numYear); ...
-1 votes
1 answer
91 views
Combine lists of 2 different objects into list of single object using Java 8 Stream API
I have two lists as below: List ids = Arrays.asList(1,2,3); List reps = Arrays.asList("abc","pqr","xyz"); Now I want to create list of Prediction objects with values ...