function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nitish Singh 22Nitish Singh 22 

How to sort alphanumeric data in Apex

I have data in the format      7.5.100.1225", "7.5.100.2736", "7.5.100.05286", "2018.1.3", "2018.1.1", "2", "10", "1", "2018.5.3".

I want to sort them. Any ideas ???

 
Raj VakatiRaj Vakati
Keep them list and sort it 
List<String> intVal= new List<String>() ;
intVal.add('7.5.100.1225');
..add all values

intVal.sort();

 
Nitish Singh 22Nitish Singh 22
No it does not sort .  Theproblem is we have numeric data in String format .
Ajay K DubediAjay K Dubedi
Hi Nitish, 

Below sample code can fullfill your requirements. Hope this will work for you.

List<String> lstStr = new List<String>{'7.5.100.1225', '7.5.100.2736', '7.5.100.05286', '2018.1.3','2018.1.1','2','1','10','2018.5.3'};
lstStr.sort();
System.debug('Sorted List::'+   lstStr);

Please mark this as best answer if this solves your problem.

Thank you
Ajay Dubedi