How do I learn to use Java commons-collections?

久未见 提交于 2019-12-22 06:08:06

问题


Weird title, I know, let me explain.

I am a developer most familiar with C# and Javascript. I am completely sunk into those semi-functional worlds to the point that most of my code is about mapping/reducing/filtering collections. In C# that means I use LINQ just about everywhere, in Javascript it's Underscore.js and jQuery.

I have currently been assigned to an ongoing Java project and am feeling rather stifled. I simply do not think in terms of "create an array, shuffle stuff from one to another". I can (and did) create my own versions of the main map/reduce functions using anonymous types implementing interfaces but why re-invent the wheel? The project I am currently on already has commons-collections-3.1.jar and looking through the classes contained it seems like it likely can do everything that I want and more.

For the life of me, I can't find how to actually use it. Looking through the dozens of classes therein is not very helpful and the only thing I can google up is the api doc which is equally as helpful.

How do you use it to Map/Select, Filter/Where, Reduce/Aggregate? Is there anywhere that gives an actual tutorial on this library?


回答1:


(Comment as answer for formatting purposes.)

Not so much, other than the limited user guide.

That said, I'm not sure where specifically you're having problems--filtering and selecting is mostly wrapped up in the functors package, and utilized by the CollectionUtils class.

While you're not looking for a replacement, you might find things like Guava or Lambda4J a bit more similar to what you're used to (within Java's constraints), and they're a bit less verbose.




回答2:


Try these links :

http://commons.apache.org/collections/userguide.html (basic tutorial) http://larvalabs.com/collections/tutorial.html (advanced tutorial with generic)




回答3:


@george-mauer, you might have to rely on articles like this or a book like Jakarta Commons Cookbook. I have also found it rather useful to learn by creating samples of my own.



来源:https://stackoverflow.com/questions/8656989/how-do-i-learn-to-use-java-commons-collections

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!