linq - How to query a list of a class in java -
i have class named class1 2 members, member1 , member2. want query on arraylist of class1 based on member1. in c# easy using linq. , found out in java can use libraries has proposed in:
is there java equivalent linq?
however don't have time learn library, has loooot of jar files in library , don't know 1 should import use functionality need. seems takes time. can give me programming hint, equivalent program can replaced query. seems cannot think out of box of linq. there way query without using these kinds of libraries?
linq can lot of things , there no single alternative it. java has no linq library, it's .net thing. can lot of common linq operations in java 8 though streams , functional programming, such example:
class1[] arr = ... list<class1> filteredlist = stream(arr).filter(e -> e.member1 == val).collect(tolist());
this generates list of elements member1
equals val
.
for more examples, i'll refer package: http://download.java.net/jdk8/docs/api/java/util/stream/package-summary.html
if java 8 not available, have resort using simple loops (or downloading library you).
Comments
Post a Comment