-5

how to sort an array with any number of elements in java?

I create an array that allows the user to choose the number of elements but I don't know how to sort it.

this is the array code

Scanner input = new Scanner(System.in);
            System.out.print("Enter the size of the array: ");
            int r = input.nextInt();
            int[] list = new int[r];
            init(list);
3
  • 4
    Not trying to be rude but you get an answer to this by literally googling your exact question title. What kept you from doing so? Commented Mar 11, 2020 at 9:49
  • no they create array and sort it in seem method, sorry Commented Mar 11, 2020 at 9:49
  • 2
    Sorry, this is just not true. This is such a well covered and basic topic. Commented Mar 11, 2020 at 9:49

1 Answer 1

1

You can try

Arrays.sort(list);
Sign up to request clarification or add additional context in comments.

4 Comments

can I try it in another method?
@TalalAlosaimi have you tried it?
can i ask u what is mean (list) ?
@TalalAlosaimi list is a variable you use in your code. You pass it to the function Arrays.sort as a parameter.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.