https://donraab.medium.com/go-primitive-in-java-or-go-in-a-box-c26f5c6d7574 Sitemap Open in app Sign up Sign in Medium Logo [ ] Write Search Sign up Sign in [1] Go Primitive in Java, or Go in a Box Donald Raab Donald Raab 6 min read * Oct 25, 2025 -- 1 Listen Share We can have our eight Java primitives and travel light in collections too. Press enter or click to view image in full size Photo by I'M ZION on Unsplash It's hard to go fast when you're in a box Java has eight primitives. For better or worse, we've had them in Java for over 30 years. We use primitives all the time (e.g. loops, if-statements, math, etc.), even when we don't use them directly (e.g. String). Java has array type support for all eight primitives. Java has three primitive Stream types (IntStream, LongStream, DoubleStream). Java has zero primitive Collection types. You have to box primitives to use them in collections. This means wrapping boolean, byte, char, short, int, float, long, double in their object wrapper equivalents, Boolean, Byte, Character, Short, Integer, Float, Long, Double. This is unfortunate. This is the nicest alternative I could come up with instead of saying what I really think, which is, this sucks. I stopped caring about this "unfortunate situation" thirteen years ago. We added primitive collections to Eclipse Collections because we saw no near or distant future where primitive collection support would exist in Java natively. We got to work and built solutions to travel light with Java collections a long time ago. You can travel light now as well if you want or need. If there's something missing that you need, Eclipse Collections is open source and open for contributions. New contributors wanted! It's cheaper and faster to travel light I could show you benchmarks and memory savings of using primitive collections instead of boxed collections. If you need to see these to be convinced of the benefits of primitive collection support in Java, then you probably don't need support for primitive collections in Java. No need to read any further. Please accept this complimentary set of eight boxes for your collection travels. If you understand and have a need for primitive collections, Eclipse Collections may have some solutions for you. Read on. Eight is enough Eclipse Collections has support for the following primitive collection types. * List (all eight primitives) * Set (all eight primitives) * Stack (all eight primitives) * Bag (all eight primitives) * LazyIterable (all eight primitives) * Map (all combinations except boolean as keys) * Interval (Int and Long) * String (char and int) For List, Set, Stack, Bag, and Map, there are both Mutable and Immutable versions of the containers. There is only immutable primitive support for Interval and String types. LazyIterable for primitives is read-only. Instantiate Them Using Factories Symmetry and uniformity are very important design considerations in Eclipse Collections. While perfect symmetry is challenging to achieve, there is "good enough" symmetry for most types in the library. The following slide from the dev2next 2025 talk, "Refactoring to Eclipse Collections", shows the combination of factories available. Credit to Vladimir Zakharov for creating this concise slide. Press enter or click to view image in full size Slide 5 from the "Refactoring to Eclipse Collections" talk at dev2next 2025 As you might notice on this slide, there are currently missing primitive collection types. There are no BiMap, Multimap, SortedBag, SortedSet, SortedMap types for primitives today. That can change over time, if folks have a specific need. We only add types to Eclipse Collections when there is a real need. Why no primitive BooleanMap? The type Map in Java has a particular design smell. We specifically designed the primitive collection types in Eclipse Collections so there are no BooleanObjectMap type or Boolean Map types. Disallowing this kind of type may seem like a poor design decision to folks who enjoy Map-Oriented Programming. After all, the the Collectors.partitioningBy() method returns Map>, so it must be a good design right? Not all questions have a simple answer, so some questions deserve an entire blog. Map-Oriented Programming in Java Using MOP may be convenient sometimes but can also be messy. levelup.gitconnected.com In modern versions of Java (Java 17+ for LTS users), you can use a Java record to create a concise strong type for what might be considered more generally as a Pair. Eclipse Collections also has Pair, and all combinations of primitive and object Pair types (e.g. IntObjectPair, ShortBytePair, LongBytePair, etc). These are better, safer alternatives to using a Map type. What about primitive support for lambdas? Eclipse Collections has had primitive collection support since before Java had lambdas (around 2012). Just like the object collections in Eclipse Collections, the primitive collections were designed with a feature rich API. I knew Java would get lambdas eventually, I just wasn't sure when exactly. My ten year quest for concise lambda expressions in Java One developer's mission to hold off the horde of for loops in Java. medium.com By the time we added primitive collection support to GS Collections, I believed Concise Lambda Expressions would be included in Java 8. The fundamental problem with lambda support for primitives is the same as collections support for primitives. There is no support for Generic Types over Primitives in Java today. This is a feature that may eventually arrive with Project Valhalla. My ten year quest for lambda support in Java has been absolutely dwarfed by my twenty-one year wait for generic types over primitives. I shared what I have been wishing and waiting for in Java in this blog. What are you wishing or waiting for in Java? Java grants new wishes every six months in feature releases. blog.stackademic.com TL;DR... This is what it looks like when you decide to stop wishing or waiting, and just get to work making a Functional Interface named Procedure/Procedure2 (aka Consumer/BiConsumer) work for the primitive types. This is only one of three Functional Interface type categories. There are also Function0/Function/Function2 and Predicate /Predicate2. The combinatorial explosion of these types is explained further in the blog and the "Eclipse Collections Categorically" book. Press enter or click to view image in full size Functional "Procedure" Interfaces for primitive types in Eclipse Collections Blogs, Code Katas, and other Resources If you are interested in learning more about the primitive collection support in Eclipse Collections, the following resources can help. Blogs The missing Java data structures no one ever told you about -- Part 3 Learn about primitive collection support in Eclipse Collections. medium.com How to collect a Java Stream into a primitive Collection Discover a primitive collection bridge for Java Stream to avoid boxing. medium.com Primitive Collections in Eclipse Collections | Baeldung Learn about primitive collections in Eclipse collections, performance and how to interact with them. www.baeldung.com Code Katas Lost and Found Kata in Eclipse Collections Kata repo. There is a solutions folder for this kata as well. eclipse-collections-kata/lost-and-found-kata at master *... Eclipse Collections Katas . Contribute to eclipse-collections/ eclipse-collections-kata development by creating an... github.com Book The book "Eclipse Collections Categorically: Level up your programming game" was first published in March 2025. The book has excellent coverage of working with both object and primitive collections in Eclipse Collections. Various versions of the book are linked from the publisher here. The book is also currently available for free to Amazon Kindle Unlimited subscribers. Reference Guide There is an AsciiDoc Reference Guide for Eclipse Collections with a dedicated section on primitive collections here. Final Thoughts The extensive primitive collections support in Eclipse Collections has been one of its most popular features. The combination of primitive collections with lambda-enabled API and support for mutable and immutable types is unmatched in any other Java collections library. These are hard problems to solve, but they have been solved problems in Eclipse Collections for well over a decade. It will be great when Project Valhalla is finally realized and released in Java. Maybe you can afford to wait for Project Valhalla to arrive and finally build the applications and libraries you really want to build. I'm glad we got to work on supporting primitive collections in Eclipse Collections when I was in my early forties. Now I'm in my mid-fifties, and I have decided I'm getting too old to wait for language miracles to arrive. Java has been good enough since Java 8, and gets better with every release. I go primitive any time I need to. I don't need to wait for anything. You can either get to work using what's available today, or wait and hope for someone to eventually unbox the box you've been travelling in. Go primitive in Java, or go in a box. Your choice. Thanks for reading! I am the creator of and committer for the Eclipse Collections OSS project, which is managed at the Eclipse Foundation. Eclipse Collections is open for contributions. I am the author of the book, Eclipse Collections Categorically: Level up your programming game. Java Eclipse Collections Open Source Java Lambda Java Collection -- -- 1 Donald Raab Donald Raab Written by Donald Raab 2.4K followers *338 following Java Champion. Creator of the Eclipse Collections OSS Java library ( https://github.com/eclipse-collections). Inspired by Smalltalk. Opinions are my own. Responses (1) See all responses Help Status About Careers Press Blog Privacy Rules Terms Text to speech