I need some help to filter an array with my function that I am getting data. I tried to create my own function to filter an array but for some reason it is not doing it. Can any one check my code of what I have done wrong. I need help to filter an array. I.E: when user types 2 letters to filter and show couple of list based of those letters. Thanks!
Here is my code:
public ArrayList<String> cPyList() throws SQLException, NamingException {
ArrayList<String> cPySearchList = new ArrayList<String>();
CallableStatement ps = null;
Connection conn = null;
ResultSet rs = null;
try {
conn = DataUtility.getDataSource().getConnection();
if (conn == null) {
throw new SQLException("Can't get database connection");
}
ps = conn.prepareCall(strCPy);
ps.clearParameters();
ArrayList list = new ArrayList<>();
rs = ps.executeQuery();
while (rs.next()) {
cPySearchList .add(rs.getString(1) + " (" + rs.getInt(2) + ")");
}
} finally {
if (rs != null) {
rs.close();
}
if (ps != null) {
ps.close();
}
if (conn != null) {
conn.close();
}
}
return cPySearchList ;
}
private static List<String> returnFilteredResult(List<String> lines, String filter) {
List<String> result = new ArrayList<>();
for (String line : lines) {
if (!"cPySearchList".equals(line)) {
result.add(line);
}
}
return result;
}