I'm having trouble and, although I'm pretty good with java, for some reason I'm getting a weird looping bug that I can't seem to squash
Here is the method that has the issue ``` private ArrayList getLocations(String[] names) { String str; String[] fixedNames = removeCopies(names); int count = 0; int lineNumber = 1; boolean done = false; ArrayList instances = new ArrayList(); for (String name : names) { try { instances.add(name); Scanner scan = new Scanner(new File( "C://Users//Owner//Desktop/test.txt")); while (scan.hasNextLine()) { String line = scan.nextLine(); Pattern p = Pattern.compile(name); Matcher m = p.matcher(line); while (m.find()) { count++; } if (count >= 1) { for (int j = 0; j < count; count--) { instances.add(lineNumber); } count = 0; } else { count = 0; instances.add(name); } lineNumber++; } } catch (FileNotFoundException ex) { Logger.getLogger(HashTable.class.getName()).log(Level.SEVERE, null, ex); } } for (Object instance : instances) { System.out.println(instance); } return instances; } ```
When I run this, I get this result (times like....... 1000) ``` java.util. 1 java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. 1 java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. 15 15 15 15 15 15 15 15 15 15 15 15 15 1
That's not the whole arraylist. Just a small chunk of it. It's only supposed to have one instance of each name in it.
Join our real-time social learning platform and learn together with your friends!