Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-Select from list

Tags:

java

list

swing

In my Java application, i need some sort of multiple-selection from a list,is there any way except a self implemented funktion like this:

private List<T> list = someListClass(); //Contains the data

public List<T> getByKey(Key key){
   List<T> returnList = someListClass();
   for(Element e : list){
      if(e.qualifiedBy(key)) returnList.add(e);
   }
   return returnList;
}
like image 690
Merlin Bögershausen Avatar asked Sep 19 '26 09:09

Merlin Bögershausen


1 Answers

Your method is fine.

With Java8 lambdas, the above will be easier to write:

public List<T> getByKey(Key key){
    return list.stream().filter(e -> e.qualifiedBy(key)).into(someListClass());
}

But before that, what you have is the simplest thing.

like image 199
JB Nizet Avatar answered Sep 20 '26 23:09

JB Nizet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!