Using Jsoup, I parse the HTML from the site to populate the ArrayList with what I needed to get from the website. So now I have an ArrayList that is populated with lines. I want to find an index in this list that contains a specific row. For example, I know that somewhere in the list, in some index, there is a string (literal) "Claude", but I can not imagine the code that finds the contains "Claude" index in an ArrayList ... that's what I tried but returns -1 (not found):
ArrayList < String > list = new ArrayList < String > (); String claude = "Claude"; Document doc = null; try { doc = Jsoup.connect("http://espn.go.com/nhl/team/stats/_/name/phi/philadelphia-flyers").get(); } catch (IOException e) { e.printStackTrace(); } for (Element table: doc.select("table.tablehead")) { for (Element row: table.select("tr")) { Elements tds = row.select("td"); if (tds.size() > 6) { String a = tds.get(0).text() + tds.get(1).text() + tds.get(2).text() + tds.get(3).text() + tds.get(4).text() + tds.get(5).text() + tds.get(6).text(); list.add(a); int claudesPos = list.indexOf(claude); System.out.println(claudesPos); } } }
Maxk
source share