About 207,000 results
Open links in new tab
  1. Bubble sort on 2D Array Java - Stack Overflow

    Apr 25, 2014 · What you would need to do is to compare the Integer values of the array: The reason you don't include j is because you are only sorting by the value of the first column. 2dArray [i] [0] gets you the value of your counter at that particular row. I've also seen some other stuff in your code that could use fixing:

  2. Row wise sorting a 2D array - GeeksforGeeks

    Apr 3, 2025 · Given a 2D array, sort each row of this array and print the result. Examples: Input: mar[][] = [ [77, 11, 22, 3], [11, 89, 1, 12], [32, 11, 56, 7], [11, 22, 44, 33] ] Output: mat[][] = [ [3, 11, 22, 77], [1, 11, 12, 89], [7, 11, 32, 56], [11, 22, 33, 44] ] Input: mat[][] = [ [8, 6, 4, 5], [3, 5, 2, 1], [9, 7, 4, 2], [7, 8, 9, 5] ]

  3. Sorting a 2D Array according to values in any given column in Java

    Oct 22, 2024 · The idea is to use Arrays.sort in Java. Syntax: Arrays.sort(arr, (a,b)->a[0]-b[0]); Example: Java

  4. A Comprenhensive Guide on Bubble Sort For 2D Array in Java

    Jul 4, 2023 · This code snippet demonstrates the implementation of the bubble sort algorithm for sorting a 2D array in Java. The bubbleSort method takes a 2D array as input and sorts each row of the array in ascending order using the bubble sort algorithm.

  5. Bubble Sort for 2D Array in Java - EnableGeek

    Bubble sort for 2D arrays in Java works by iterating over each row of the array and applying the bubble sort algorithm to each row separately. The bubble sort algorithm involves comparing adjacent elements in the row and swapping them if they are in the wrong order.

  6. Using Bubble-Sort for Two-Dimensional Array in Java

    Apr 24, 2017 · So that just means that every row is sorted, not that the array is sorted. Then all you need to do is iterate your array, and apply your bubble sort to each row separately. I am looking to modify a bubble sort that I used for a one-dimensional array in order for it to sort a two-dimensional array.

  7. Sort 2D Array Across Rows in Java - Online Tutorials Library

    Jul 31, 2023 · This article will demonstrate how we can sort a 2D array across rows with the help of a java program. We will be using three different methods to get to the solution. Firstly we will use the vector() method , secondly the library function Array.sort and …

  8. How to Sort a 2D Array in Java - HatchJS.com

    A: To sort a 2D array by row, you can use the `Arrays.sort()` method. This method takes a multidimensional array as its argument and sorts it by the elements in the first row. To sort by the elements in a different row, you can use the `Comparator` interface.

  9. java - Bubble-Sort with 2D Array - Stack Overflow

    Dec 6, 2009 · you can have an ordinary array of Person objects, sorting them with your bubble sort algorithm. You can create several custom comparators that compare either id, name, surname or address to you bubble sort algo. The signature of the sort method should be something like. public Person[] bubbleSort(Person[] persons, Comparator comp)

  10. How to Sort 2D Array in Java - Delft Stack

    Feb 12, 2024 · This article discusses how to sort a 2D array in Java using two distinct approaches: column-wise sorting using the Comparator interface and row-wise sorting using the Arrays.sort() method.