How do i sort a array of numbers having 10^6 digits using Java in an efficient way -
how sort array of numbers having 10^6 digits using java in efficient way
i pretty sure can strings
but there other method without using strings in java.?
use biginteger , take advantage of java's sort api
import java.math.biginteger; import java.util.arraylist; import java.util.collections; public class main { public static void main(string[] args) { arraylist<biginteger> list = new arraylist<>(); list.add(new biginteger("12")); list.add(new biginteger("1223876987587658765876732097234987236497823649287346987324609234786923748601298763290444")); list.add(new biginteger("126235812763548126375182763518236512983761927836012983719274629183746912874612948761298746912837342")); list.add(new biginteger("32342")); collections.sort(list); system.out.println(list); } }
this prints:
[12, 32342, 1223876987587658765876732097234987236497823649287346987324609234786923748601298763290444, 126235812763548126375182763518236512983761927836012983719274629183746912874612948761298746912837342]
Comments
Post a Comment