r/javahelp • • May 07 '20

Codeless Java Developers: what are the common data structures you usually use on production

To professional java dev here, what are the common data structure youve been using and which data structure you strongly suggest for beginners, like me, to study carefully

40 Upvotes

38 comments sorted by

View all comments

Show parent comments

3

u/MrSquicky May 07 '20

I believe that a pair of Countdown Latch objects, properly applied, can solve all communication problems including peace in the Middle East.

I'd love to hear more about this. I'm using Spring's DeferredResult in what I think is a similar context. I'm aware of CountDownLatches, but I've never used them.

0

u/DepletedSensation May 07 '20

Im not 100% sure what he might mean here. But like JavaScript can return more than one object from a list based off of a filter or value. (Say if price is less than 5$, or if title starts with "A")

To my knowledge there is no built in function for this in Java, you have to write a stream or your own method that returns a list with this desired filter applied.

3

u/MrSquicky May 07 '20

Oh, no, that I get and totally agree with. He's looking for a decomposable tuple return. Me too.

So like you could return ("foo", 10) from a function and read that as (text, count) and have text = "foo" and count = 10.

Python does this really nicely. Kotlin has it too, but it's not quite as nice because, as far as I know, it needs to be typed (although I can't imagine wanting to return more than 3 things from a function anyway). It kind of sucks to return Object[] and then need to read it out of it.

---

CountDownLatches are used with Threads for controlling concurrent access. I'm aware of the concept, sort of. If my understanding is right, they're sort of like Futures with a numeric countdown you can attach to it so that when the countdown goes to zero, it completes. I've never used them and would be interested in learning how other people are using them. I love finding out cool usages of parts of a languages that I didn't know about.

I found myself in a situation where we're doing real time messaging, but not able to use web sockets because of technical limitations, so I'm using long polling by leveraging Spring's DeferredResult and I'm not sure if we're talking in the same area or not.

1

u/DepletedSensation May 14 '20

Yea I mean the way I would handle that is by using Pairs and stuff.

Also, about the Future and Threads, well it's so rarely we get to use them unless we really need to right? It kind of sucks. I can deffinitely recommend a book, "Java Concurrency In Practice" by Goetz. He helped design the Concurrency package in Java 6. :)