Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

260
Views
Ordenar lista con fecha de cadena [Kotlin]

Tengo arraylist typeBeanArrayList donde el elemento es algo así como una fecha: por ejemplo:

 [30-03-2012, 28-03-2013, 31-03-2012, 2-04-2012, ...]

¿Cómo puedo ordenar en orden descendente?

Código:

 typeBeanArrayList = database.getSingleCustomerDetail(c_id!!) //get data from SQlite database creditListAdapter = CreditListAdapter(typeBeanArrayList) rv_credit_list!!.adapter = creditListAdapter //Bind data in adapter

Gracias por adelantado...

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Gracias @svkaka por la información.

Solo noté una línea de la respuesta de @svkaka: .sortByDescending { it.length } .

y cambio en mi código como:

 typeBeanArrayList.sortByDescending{it.date}

La clasificación funciona perfectamente.

over 4 years ago · Santiago Trujillo Report

0

Si tiene una lista de String que representan fechas, una forma de ordenarlas en orden descendente es:

 val dates = listOf("30-03-2012", "28-03-2013", "31-03-2012", "2-04-2012") val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy") val result = dates.sortedByDescending { LocalDate.parse(it, dateTimeFormatter) } println(result)

Esto imprimirá:

 [28-03-2013, 2-04-2012, 31-03-2012, 30-03-2012]

Tenga en cuenta que los métodos sortedByXXX devuelven una nueva lista, es decir, no se ordenan en su lugar

over 4 years ago · Santiago Trujillo Report

0

Puede usar algo como esto si está usando un modelo personalizado

 typeBeanArrayList.sortedWith(compareByDescending<YourModel> { it.date() })
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!