
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Perform Bubble Sort on strings in Java
To perform Bubble Sort, try the below given code. In this each each pair of adjacent elements is compared and the elements are swapped if they are not in order.
The following is an example.
Example
public class Demo { public static void main(String []args) { String str[] = { "s", "k", "r", "v", "n"}; String temp; System.out.println("Sorted string..."); for (int j = 0; j < str.length; j++) { for (int i = j + 1; i < str.length; i++) { // comparing strings if (str[i].compareTo(str[j]) < 0) { temp = str[j]; str[j] = str[i]; str[i] = temp; } } System.out.println(str[j]); } } }
Output
Sorted string... k n r s v
- Related Questions & Answers
- a 8085 Program to perform bubble sort based on choice
- Program to perform bubble sort based on choice in 8085 Microprocessor
- Bubble sort in Java.
- 8085 Program to perform sorting using bubble sort
- 8085 Program to perform bubble sort in descending order
- 8085 Program to perform bubble sort in ascending order
- Bubble Sort
- Program to perform bubble sort in ascending order in 8085 Microprocessor
- Java program to implement bubble sort
- Java Program for Recursive Bubble Sort
- Bubble Sort program in C#
- Bubble Sort in Go Lang
- Difference Between Bubble Sort and Selection Sort
- 8085 program for bubble sort
- Python Program for Bubble Sort
Advertisements