2016-11-21 151 views
0

如何將List轉換爲GroupMatcher?如何將列表<String>轉換爲GroupMatcher <JobKey>

我的代碼就像這樣。

List<String> jobGroupNames = scheduler.getJobGroupNames(); 

現在我要檢查

for (GroupMatcher<JobKey> jobGroup : jobGroupNames) { 
} 

這裏jobGroupNames是列表,所以我得到這個錯誤

Type mismatch: cannot convert from element type String to GroupMatcher<JobKey> 
+0

試圖讓GorupMatcher像'GroupMatcher.groupEquals( jobGroupName)''for scheduler.getJobGroupNames()' –

+0

它不起作用,'List '參數不適用於'groupEquals )' – zeji

+0

因爲你做錯了。嘗試閱讀如何迭代列表。 http://crunchify.com/how-to-iterate-through-java-list-4-way-to-iterate-through-loop/ –

回答

0
jobGroupNames is a list of String, That's why you should iterate like below. 

// loop jobs by group 

List<String> jobGroupNames = scheduler.getJobGroupNames(); 

for (String groupName : jobGroupNames) { 

// And to get Job keys : 

    for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) { 
    } 
} 
相關問題