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

259
Views
Sort list with string date [Kotlin]

I have arraylist typeBeanArrayList where element is some like a date: for example:

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

How can I sort in descending order.

Code:

typeBeanArrayList = database.getSingleCustomerDetail(c_id!!) //get data from SQlite database

creditListAdapter = CreditListAdapter(typeBeanArrayList)
rv_credit_list!!.adapter = creditListAdapter //Bind data in adapter

Thanks in advance...

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Thank you @svkaka for information.

I just notice one line from @svkaka answer : .sortByDescending { it.length }.

and i changes in my code like :

typeBeanArrayList.sortByDescending{it.date}

Sorting is perfectly work.

over 4 years ago · Santiago Trujillo Report

0

If you have a list of Strings representing dates, one way to sort them in descending order is:

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)

This will print:

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

Note that sortedByXXX methods return a new List, i.e., they don't sort in place

over 4 years ago · Santiago Trujillo Report

0

You can use something like this if you are using a custom model

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!