Alright I need a little help here I want to compare to arraylists and if a match occurs return the value of whatever item matched as a string. Thanks alot.
Comparing arrayList
Collapse
X
-
Ok that didn't really help but thanks here's my code
Code:import java.sql.Statement; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.util.ArrayList; /** * @date February 14, 2009 * @author Colin Hanshaw */ public class ProcessChecker { String parsedString; String test; int counter = 0; ArrayList parsedStrings = new ArrayList(); ArrayList blockedApps = new ArrayList(); private static String dbURL = "jdbc:derby://localhost:1527/MyDesk;user=administrator;password=password"; Connection conn = null; boolean running = true; public static void main(String[] args) throws Exception { ProcessChecker checker = new ProcessChecker(); } public ProcessChecker() throws Exception { createConnection(); listRunningProcesses(); quereyDatabase(); tryFind(); } private void createConnection() { try { Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance(); conn = DriverManager.getConnection(dbURL); } catch (Exception except) { except.printStackTrace(); } } public void listRunningProcesses() { try { Runtime runtime = Runtime.getRuntime(); String cmds[] = {"cmd", "/c", "tasklist"}; Process proc = runtime.exec(cmds); InputStream inputstream = proc.getInputStream(); InputStreamReader inputstreamreader = new InputStreamReader(inputstream); BufferedReader bufferedreader = new BufferedReader(inputstreamreader); String line; while ((line = bufferedreader.readLine()) != null) { parsedString = parseString(line); parsedStrings.add(new String(parsedString)); counter++; } removeElements(); } catch(Exception ex) { System.out.println("Tasklist might not exist"); } } public String parseString(String incString) { String myParsedString = incString; String delims = "[ ]+"; String[] tokens = incString.split(delims); myParsedString = tokens[0]; return myParsedString; } public void removeElements() { parsedStrings.remove(0); parsedStrings.remove(0); parsedStrings.remove(0); } public void quereyDatabase() throws Exception { try { Statement stmt = conn.createStatement(); ResultSet rs; rs = stmt.executeQuery("select BLOCKEDITEMS from ADMINISTRATOR.BLOCKEDLIST"); while ( rs.next() ) { String blockedItem = rs.getString("BLOCKEDITEMS"); blockedApps.add(new String(blockedItem)); } conn.close(); } catch (Exception e) { System.err.println("Got an exception! "); System.err.println(e.getMessage()); } } public void tryFind() { } /*public void endProcess() { if(line.startsWith(testString)) { runtime.exec("taskkill /IM " + testString); } }*/ }
parsedStrings contains
String "Chris"
String "Nick"
String "Tom"
String "Melissa"
String "Wombat"
blockedApps contains
String "Tyler"
String "Chris"
String "Art"
String "Melissa"
I want the tryFind() method to compare the two arraylists
So it would return true for Chris
Then would return true for Melissa
Thanks hope that made more sence.Comment
Comment