Calling a String Array to name a new integer array

I’m trying to write a loop that will generate a collection of new integer arrays based on the elements in a string ArrayList, but unfortunately Processing is having trouble calling the ArrayList in the definition of each array.

The problem seems to be that Processing doesn’t know I’m just trying to call the element in the ArrayList to name another Array.

StringList characs;
characs = new StringList();
characs.append(“Harry”);
characs.append(“Hermione”);
characs.append(“Ron”);
characs.append(“Hagrid”);
characs.append(“Dumbledore”);
characs.append(“Voldemort”);
characs.append(“Draco”);
characs.append(“Longbottom”);
characs.append(“McGonagall”);
characs.append(“Snape”);
characs.append(“Quirrell”);

String item;

for (int a = 0; a <= characs.size(); a++) {

item = (characs.get(a));
   item2 = (characs.get(a+1));
int[] string(item+'_ind') = new int[hp.length]; // Where string(item+'_var') would convert to something like 'Harry_ind' and a new integer array would be created.
     int[] string(item+'_'+item2+'_ind') = new int[hp.length]; // Where string(item+'_'+item2+'_ind')  would convert to something like 'Harry_Hermione_ind' and a new integer array would be created.

}

And, yes! I am trying to identify every time the different characters are mentioned in Harry Potter!

Much thanks for your help.

That is not ging to work in Processing Java mode since variable names must be declared at compile time and not runtime.
Are you simply trying to count the number of times the word appears in text?

2 Likes

Sounds like a Hashmap topic

What Chrisir is saying: use a HashMap to store your integer values under String keys:

https://processing.org/reference/HashMap.html

2 Likes

Or an IntDict: Processing.org/reference/IntDict.html

2 Likes