1
votes
 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
Hard to say without seeing more code. My guess is that you're instantiating the Vectors inside a loop. - Bart Kiers
This was rightt, thankyouu very much! Too bad you didn't post this as an answer lol so I can't mark any as correct :[ Hate it when I do this though lol, post a question and the answer ends up being something really obvious! - Becky

1 Answers

1
votes

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.