Over a million developers have joined DZone.

Sometimes You Need Tuples in Java. Or Not

· Java Zone

Learn more about the advantages of moving from a monolithic to microservices architecture.  Brought to you in partnership with IBM.

Tuple is an ordered list of elements. In Java that is List<Object>. Even though it exists there is an extra need from programmers for tuples. You can see that there is a package named javatuples that defines tuples that contain 1, 2 up to 10 elements. (Btw: There is a class in the package named Unit that contains one element. WAT?) There is a longdiscussion on stackoverflow about tuples.

But where does it come from? Why do some Java programmers long for tuples? The answer is that tuples are part of the language constructs of other languages. They date back to such old ages that only program archeologist can remember. Languages like LISP use tuples. Python is also lurking here from the last century. Why did they implement a feature like tuples? Perhaps it seemed to be a good idea. If it was not coming from the past, Java developer would not long for it. Which itself is a hint: do you really need it? But the fact is fact:

Java misses tuples. THIS IS A LIE!

Which is not true for two reasons:

  1. There is no need for tuples.
  2. There is a built in type in Java that can handle tuple

There is an interface named java.util.Map.Entry that is there just to hold two objects and there is a simple implementation java.util.AbstractMap.SimpleEntry. Thus Java does not misses tuples and neither do I.

From Idea to Application gives you the architecture to quickly build, manage and run a range of applications (web, mobile, big data, new smart devices, etc.) on an open-standard, cloud-based platform. See why developers are using IBM Bluemix. Brought to you in partnership with IBM.


Published at DZone with permission of Peter Verhas, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}