本当に何を意味するのかまったくわかりませんが、コードに深刻な根本的な欠陥がいくつかあるので、それらに対処します.
//We can define variables outside a while loop
//and use those inside the loop so lets do that
Map trusterMap = new HashMap<String,ArrayList<String>>();
//i is not a "good" variable name,
//since it doesn't explain it's purpose
Int count = 0;
while(myScanner.hasNextInt()) {
//Get the truster and trustee
Int truster = myScanner.nextInt();
Int trustee = myScanner.nextInt();
//Originally you had:
// String listname = truster + i;
//I assume you meant something else here
//since the listname variable is already used
//Add the truster concated with the count to the array
//Note: when using + if the left element is a string
//then the right element will get autoboxed to a string
//Having read your comments using a HashMap is the best way to do this.
ArrayList<String> listname = new ArrayList<String>();
listname.add(truster);
trusterMap.put(truster + count, listname);
i++;
}
さらに、配列に供給される Int のストリームを myScanner に格納していますが、それぞれの意味は大きく異なります (truster
およびtrustee
)。ファイルまたはユーザー入力からこれらを読み込もうとしていますか? これを処理するためのより良い方法があり、あなたが何を意味するかについて以下にコメントすると、提案された解決策で更新されます.