2017-05-23 5 views

답변

2

당신은

// any number of non-digits (consumed greedily), 
// followed by any number of digits (consumed greedily, as a group named "value"), 
// followed by anything 
Pattern pattern = Pattern.compile("\\D*(?<value>\\d*).*"); 

idColumn.setComparator(Comparator.comparingInt(id -> { 
    Matcher matcher = pattern.matcher(id); 

    // value to return if no match: 
    int defaultValue = 0 ; 

    if (matcher.matches()) { 
     // get the portion of the match that matched the group named "value": 
     String value = matcher.group("value"); 
     if (value.isEmpty()) { 
      return defaultValue ; 
     } else { 
      // convert to an int: 
      return Integer.parseInt(value); 
     } 
    } else { 
     return defaultValue ; 
    } 
})); 
+0

감사를 할 수

TableColumn<SomeEntity, String> idColumn ; 

을 가정 할 때, 나는 이것을 시도 할 것이다! – Ulkurz

관련 문제