views:

58

answers:

1
 codes = new Vector<String>();
 titles = new Vector<String>();
 urls = new Vector<String>();
 lecturers = new Vector<String>();
 while (m.find()) {
    String courseCode = m.group(1);
    String courseTitle = m.group(2);
    String courseURL = url;
    String lecturerName = m.group(4);
    codes.add(courseCode);
    titles.add(courseTitle);
    urls.add(courseURL);
    lecturers.add(lecturerName);
 }

I'm trying to get data from like 10 websites and it works alright if you just print out each group by itself eg: system.out.println(courseCode); prints out a list of 10 courseCodes but when I try to add them into these vectors it only adds the last courseCode instead of each one. So each vector SHOULD have like 10 elements but they only have 1. Is there a way to like iterate through the matches?

+1  A: 

Maybe the regex matches only one time instead of 10 times. You can check this if you count how often you iterate throught the while loop. The easiest way is to define a help variable int i=0; and increase this value inside the loop with i++; (and print it inside or outside the loop). Also check the size of the Vectors with list.size() inside the while loop to see how the size is actually growing.

Progman
i know it matches more than once because if i type system.out.println(courseCode); instead of codes.add(courseCode); it will print what i expect, but for some reason if i use codes.add(courseCode) it will only add the last match and no others and the size is always 1.
Becky