1
セルデータに以下に示す文字列と整数が含まれている私のテーブル列(「ID」)。その列のデータの部分文字列に基づいてTableViewを並べ替える方法
ID
ABC1
fgd5
hgt9
ftg7
私は後にソート次の結果を取得する必要があります
ID
ABC1
fgd5
ftg7を
hgt9
この列は、列データの整数値のみに基づいて並べ替えることができます。
セルデータに以下に示す文字列と整数が含まれている私のテーブル列(「ID」)。その列のデータの部分文字列に基づいてTableViewを並べ替える方法
ID
ABC1
fgd5
hgt9
ftg7
私は後にソート次の結果を取得する必要があります
ID
ABC1
fgd5
ftg7を
hgt9
この列は、列データの整数値のみに基づいて並べ替えることができます。
あなたは
// 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 ;
}
}));
感謝を行うことができます
と仮定すると、私はこれを試してみましょう! – Ulkurz