What is a bubble sort in java?



What is a bubble sort in java?..

Answer / Avlokna Agarwal

Bubble Sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order. Here's an example:

```java
void bubbleSort(int[] arr) {
int n = arr.length;
for (int i = 0; i < n-1; i++) {
for (int j = 0; j < n-i-1; j++) {
if (arr[j] > arr[j+1]) {
// swap arr[j] and arr[j+1]
}
}
}
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

Difference between JVM and JRE?

3 Answers   Amdocs,


Can we rethrow the same exception from catch handler?

1 Answers  


What is r * in math?

1 Answers  


What is contract between hashcode and equal method?

1 Answers  


How do I compare two strings in word in java?

1 Answers  


How to find the size of an array a)array.length() b)array.length c)array.size() d)array.size

6 Answers   Accenture,


How big is a pointer?

1 Answers  


can we have virtual functions in java?

11 Answers   Wipro,


How do you add an element to an arraylist in java?

1 Answers  


What is an object in Java and what are its benefits?

4 Answers   IBM,


How many types of thread in java? give the name

13 Answers   Cisco, NIIT,


what is collatration?

1 Answers  


Categories