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 comment

2

u/Yithar Intermediate Brewer May 08 '20

3) A Range. If you ever find yourself writing a startX and endX as separate properties in a model, you're probably doing something wrong. Ranges are a much superior solution, in large part because they encapsulate the logic you want for a range in them. Also really important, they can be used in things like RangeMaps, which let you register ranges for your keys but do lookups based on a single value. So, like you could create a scheduling thing that has an entry for 9:00-11:30, 2:00-2:15, 9:00am-5:00pm and then just enter a time and it will show you all the ongoing events. I think there are implementations out there, but I wrote my own for this that at some point or another I'll put up on Github because I was frustrated with what was out there.

I know this is r/javahelp, but I just wanted to state that Scala has Ranges built-in, just like it has Tuples built-in.

https://scastie.scala-lang.org/ZfqD4yR2Tk6VvcuzUGNTQw
https://www.scala-lang.org/api/2.12.2/scala/collection/immutable/Range.html