我正在实现一个 JTable,用户可以在其中定义时间表。 每个科目都有多个学分,我必须统计一周内所有学分的总和。显然,为此,有必要将所有重复主题计算一次(我不会将同一主题的学分计算两次)。
例如,如果 JTable 是
我想获取值数学
、英语
、科学
、哲学
、艺术
仅一次次。我尝试使用 follower 方法来做到这一点:
private void getOnce (String[] dailyLessons)
{
Set<String> weekSubjects = new HashSet<String>();
int weeklyCredits=0;
//dailylessons is a String[] that contains the lessons of the day
Collections.addAll(weekSubjects, dailyLessons);
//String[] week would contain every subject only one time
String [] week = weekSubjects.toArray(new String[0]);
//for all the subject I get its credits
for (int i=0; i<week.length; i++)
{
if (!week[i].equals("no"))
{
String [] credits= week[i].getCredits;
weeklyCredits += credits;
}
}
}
但是它不起作用。你能解释一下为什么吗?我的代码的正确版本将非常感激。
最佳答案
But it does not work. Could you explain me why?
阅读 Oracle 教程 How to use Tables
JTables View
的所有数据都存储在 ( Creating a Table Model ) XxxTableModel如果
XxxTableModel
没有任何定义,则使用DefaultTableModel
A correct version of my code will be very appreciated.
- 不错
关于java - 如何不考虑表中的重复值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18847082/