OK, I rewrote my class,I rushed so the code is not clean yet anyway now it comipiles, and running mainMethod the problem is still there.
import java.util.*;
public class myClass {
public Random myRandom;
public HashMap<String, ArrayList<String>> myMap;
public ArrayList<String> ar;
public ArrayList<String> nexts;
// ArrayList<String> follows;
public myClass(){
myRandom = new Random();
}
public void setRandom(int seed){
myRandom = new Random(seed);
}
public HashMap<String, ArrayList<String>> buildHashMap(){
HashMap<String, ArrayList<String>> myMap = new HashMap<String, ArrayList<String>>();
ArrayList<String> ar = new ArrayList<String>();
ar.add("2");
ar.add("2");
String test = "test";
String anothertest = "anothertest";
myMap.put(test, ar);
myMap.put(anothertest, ar);
return myMap;
}
public ArrayList<String> arrayListGetter(String st){
System.out.println("++++++++++++++++++++++++++++++++++");
System.out.println(myMap.size());
ArrayList ar = myMap.get(st);
return ar;
}
public void mainMethod(){
HashMap<String, ArrayList<String>> myMap = new HashMap<String, ArrayList<String>>();
myMap = buildHashMap();
System.out.println("\n\nNumber of keys found: " + myMap.size());
for (String st : myMap.keySet()){
System.out.println(st + ": ");
ArrayList<String> al = myMap.get(st);
System.out.println(al.size());
}
StringBuilder sb = new StringBuilder();
String test = "test";
System.out.println(myMap.get(test));
System.out.println(sb);
System.out.println(myMap.get(test).size());
System.out.println(myMap.get(test).size());
// ArrayList<String> follows = getFollows(key);
System.out.println("something");
int index = myRandom.nextInt(myMap.get(test).size());
System.out.println(index);
// index = myRandom.nextInt(follows.size());
String next = myMap.get("test").get(index);
sb.append(next);
System.out.println(sb);
System.out.println(myMap.get("test").getClass());
ArrayList<String> follows = new ArrayList<String>();<------new empty ArrayList
System.out.println(follows.size() + " **********");
ArrayList<String> nexts = new ArrayList<String>();
nexts = arrayListGetter ("test");
}
}
Am I missing something obvious? Thanks in advance for your time and patience.