My rowId is like the below, it will follow parent and child relationships
1
1.1
1.1.1
2
2.1
.
.
.
9
9.1
.
9.9
10
10.1
I am using the following code to sort that beans using rowid's
List<MyBean> sortedList = rootItems.stream().sorted(Comparator.comparing(MyBean::getRowId)) .collect(Collectors.toList());
if I sort like the above then it is sorting like the below
10
11
12
.
.
19
2
2.1
.
.
3
.
.
it should not be like this.
I want to sort like the example of rowid's I have given on top.
Someone suggested me to follow his code.. i.e..,
private static final Pattern SINGLE_DIGIT = Pattern.compile("\\b(\\d)\\b");
static String padWithZeroes(String InputString, int digits) {
final Matcher matcher = SINGLE_DIGIT.matcher(InputString);
StringBuffer sb = new StringBuffer();
while(matcher.find()){
matcher.appendReplacement(sb, pad(digits - matcher.group().length())+matcher.group());
}
matcher.appendTail(sb);
return sb.toString();
}
static String pad(int length) {
final char[] chars = new char[length];
Arrays.fill(chars, '0');
return new String(chars);
}
If I follow his code it is returning me a string but not the list of objects.. How can I use that code.. Please help me.