1
public ArrayList<String[]> customerArray= new ArrayList<String[]>();

The first elements are String type, I want to make them Integer and sorting.

35 Murat Kaya 236-3446789 Address: Dikmen 4. Cadde 34/2
45 Hatice AK 568-8969746 Address: Cebeci 56 cd. 34/5

It is part of this file.

4
  • what do you mean by The first elements are String type do you mean 35 and 45 ? Commented Apr 13, 2018 at 16:59
  • It's of course possible, but this is the wrong way of solving the problem. Start by transforming your arrays of strings into objects of a well-defined class, with named, typed properties, and then sort these objects. Commented Apr 13, 2018 at 17:00
  • Yes, 35 and 45. Basically, I want to sort them by id number. Commented Apr 13, 2018 at 17:01
  • Collections.sort(List<T> list, Comparator<? super T> c) Commented Apr 13, 2018 at 17:02

2 Answers 2

4

You can achieve it like so:

customerArray.sort(Comparator.comparingInt(e -> Integer.parseInt(e[0])));
Sign up to request clarification or add additional context in comments.

Comments

1

customerArray.sort((sa1,sa2)->Integer.parseInt(sa1[0])-Integer.parseInt(sa2[0]));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.