Piet Souris wrote:Indeed, and I don't think that ListZip class is simple. For instance
So, in twoLists we have that A is List and B is List. However, the zip method takes a List<A> and a List<B> as parameters. Very confusing. But take note that the generic A and B from ListZip are not the same as the generic A and B from the zip method!
Edit: my reply was a reply to Junilu's post
Edit2: indeed it is the Object::toString that causes each ListZip to be transformed into a String, and the toString is used for this.
Junilu Lacar wrote:
Mike London wrote:Maybe I misunderstand, but I can set a breakpoint on toString and it runs on the result.add()
I think you did misunderstand. The only line that would call toString() is line 21:
Piet Souris wrote:
Mike London wrote:I found the code below which appears simpler, but the question I have is why does the "result.add(...)" code call the toString() method? I thought toString() got called when you tried to System.out.println(someobject).
Well, the 'toString' method is not being called. it1 is an iterator(A) and it2 is an iterator(B) (can't use the angled brackets here, because they have a special meaning in this editor), so the calls to 'next' result in an A and a B being delivered, and from these two a new ListZip object is formed.
It is a bit simpler than mine, but mine is a tad more general, and it also deals somehow with the situation that the lists are unequal of size, This method simply stops at that point.
Liutauras Vilda wrote:But if you are happy with the result you got - all fine
Liutauras Vilda wrote:I thought you'd go with your own implementation (which is fairly simple). Didn't try Guava's this method, but I trust it does the job.
Liutauras Vilda wrote:@OP
Don't forget to "think about"/handle the cases when the lists might be not equal in terms of their sizes.
Campbell Ritchie wrote:Unfortunately, it isn't an enumeration (small e; an Enumeration with large E is something different), nor an enum, nor anything enumerated; it is simply ints as constants in the class. Had it been enumerated, as this is, you wouldn't have the problem of entering 2 and getting MARCH. You would have a compiler error from anything requiring that enum.
Mike London wrote:. . . I didn't use the Enumeration to get Calendar.JANUARY.On behalf of the other people who gave you more of an answer than I did:-
That's a pleasure
Campbell Ritchie wrote:One reason for abandoning Calendar and Date is that the month numbers in Calendar are unintuitive.