我们从UI以json的形式收到了一些数据并且对Java对象进行了控制,在此基础上我们必须过滤主列表并将该DataObject存储在filterList中。
public class DataObject implements Serializable{
private String mTaskName;
private long mCaseNumber;
......
}
//Fetching data list from session
List<DataObject> listData =(List<DataObject>)session.getAttribute("DATA_LIST");
//Variable to hold filtered data
List<DataObject> filteredData = new ArrayList<DataObject>();
public class FilterCriteria
{
private String filterName;
private String[] value;
.....
}
例如,如果我们将filterName作为TaskName和Value [“value1”,“value2”],并且第二个过滤器CaseNumber也启用了值[“2323232”,“4554544”]。我们必须在listData的主List上应用这个逻辑,并将那些在filteredData中过滤掉的记录存储起来。怎么做到这一点?
答案 0 :(得分:2)
Apache Commons Collections CollectionUtils.filter怎么样? http://commons.apache.org/proper/commons-collections/javadocs/api-3.2.1/org/apache/commons/collections/CollectionUtils.html#filter%28java.util.Collection,%20org.apache.commons.collections.Predicate%29
答案 1 :(得分:0)
我希望你也能以这种方式实现它,如果你想按行或列方式。
import java.util.*;
public class HelloWorld{
public static void main(String []args)
{
List<ArrayList<String>> two_dimension=new ArrayList<ArrayList<String>>();
//Suppose you want to make nxm dimensional list. Then you can set the values as
int rows=4;
int columns=5;
for(int i=0;i<rows;i++)
{
two_dimension.add(new ArrayList<String>());
for(int j=0;j<columns;j++)
{
two_dimension.get(i).add("element"+i+j);
}
}
//to accesss your element
boolean row=true; // lets decide to traverse by row
if(row==true)
{
for(int i=0;i<rows;i++)
{
for(int j=0;j<columns;j++)
{
System.out.println(two_dimension.get(i).get(j));
}
}
}
else
{
for(int i=0;i<columns;i++)
{
for(int j=0;j<rows;j++)
{
System.out.println(two_dimension.get(j).get(i));
}
}
}
}
}