休息几年后才回到Java。我正在尝试从一个数组中选择元素并将它们存储在另一个 Java 中。我创建了一个具有固定数量元素的相同类型的新数组。我要复制的数组不是空的,我已经打印出来了。但是当我尝试显示新数组时,值不存在 - 只是对元素的引用。我可能忽略了一些东西。我一直在寻找最后一天,但没有得到任何地方。我真的很感激一些帮助。下面的代码:
PersonDetails user = new PersonDetails(userName,userGender,userAge,userInterests);
PersonDetails [] userArray = new PersonDetails [numberOfDaters];
PersonDetails [] dateArray = new PersonDetails [numberOfDaters];
userArray = user.getArray("datingdata.txt", numberOfDaters);
dateArray = Arrays.copyOf(userArray, userArray.length);
char [][] interestArray = new char[numberOfDaters][5];
for (int z =0;z<userArray.length; z++) {
interestArray[z] =
userArray[z].getAllInterests( userArray[z].getInterests());
}
String remove = user.getOnes(interestArray);
System.out.print(remove);
StringTokenizer st = new StringTokenizer(remove);
int num = st.countTokens();
PersonDetails [] userRemoveArray = new PersonDetails [num];
while(st.hasMoreTokens()) {
int token = Integer.parseInt(st.nextToken());
for(int x =0;x<userRemoveArray.length;x++) {
userRemoveArray[x] = userArray[token];
}
System.out.println(userRemoveArray);
}
输出如下:
[LPersonDetails;@a8c488
[LPersonDetails;@a8c488
[LPersonDetails;@a8c488
[LPersonDetails;@a8c488
[LPersonDetails;@a8c488
[LPersonDetails;@a8c488
[LPersonDetails;@a8c488
[LPersonDetails;@a8c488
[LPersonDetails;@a8c488
[LPersonDetails;@a8c488
[LPersonDetails;@a8c488
提前致谢