keim Posted January 18, 2007 at 05:05 AM Report #77043 Posted January 18, 2007 at 05:05 AM Alguém me pode dar uma mãozinha, gostava de conseguir ordenar um arraylist assim de uma maneira semelhante ou pela menos simples... se fosse um array normal de datas por exemplo eu costumo implementar comparable a data, crio o metodo CompareTo e depois qd quero ordenar o array faço Arrays.sort(array_de_datas,inicio,fim) mas o Arrays.sort não funciona com arraylist...
Rui Carlos Posted January 18, 2007 at 11:12 AM Report #77055 Posted January 18, 2007 at 11:12 AM http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collections.html#sort(java.util.List) pelo que andei a ver, este método da classe 'Collections' pode ser usado com 'ArrayList' (mas nunca experimentei)... Rui Carlos Gonçalves
inginheiiro Posted January 18, 2007 at 11:24 AM Report #77056 Posted January 18, 2007 at 11:24 AM List list = new ArrayList(); list.add("1sdsdfjçslkfsdf"); list.add("1sdsçlfksdfkçsdf"); list.add("sdljflskjfskjflsjkfsdf"); Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { String s1 = (String)o1; String s2 = (String)o2; ... }}); /ing I used to have a life ... but i bought a programmable machine in 1982 ...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now