Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I guess you don't want simply the lexicographic order (the solution would be obvious).</p> <p>First, remove the ".java" part and split your string on the character "_".</p> <pre><code>int dotIndex = string.indexOf("."); String []parts = split.substring(0, dotIndex).split("_"); </code></pre> <p>You are interested in parts[1] and parts[2]. The first is easy, it's just a number.</p> <pre><code>int fileNumber = Integer.parseInt(parts[1]); </code></pre> <p>The second one is always of the form "VX" with X being a number. But this part may not exist (if it's the base version of the file). In which case we can say that version is 0.</p> <pre><code>int versionNumber = parts.length &lt; 2 ? 0 : Integer.parseInt(parts[2].substring(1)); </code></pre> <p>Now you can compare based on these two numbers.</p> <p>To make things simple, build a class FileIdentifier based on this:</p> <pre><code>class FileIdentifier { int fileNumber; int versionNumber; } </code></pre> <p>Then a function that create a FileIdentifier from a file name, with logic based on what I explained earlier.</p> <pre><code>FileIdentifier getFileIdentifierFromFileName(String filename){ /* .... */ } </code></pre> <p>Then you make a comparator on String, in which you get the FileIdentifier for the two strings and compare upon FileIdentifier members.</p> <p>Then, to get the string with "the highest value", you simply put all your strings in a list, and use <code>Collections.sort</code>, providing the comparator.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload