Kubernate

Java # Sort the String without Using Sort and Stream

 import java.util.*;


public class SortString {
public static void main(String[] args)
{
List<String> list = new ArrayList<>();
list.add("Banana");
list.add("Apple");
list.add("Mango");
list.add("Orange");

for (int i = 0; i < list.size() - 1; i++)
{
for (int j = 0; j < list.size() - i - 1; j++)
{
if (list.get(j).compareTo(list.get(j + 1)) > 0)
{
// swap
String temp = list.get(j);
list.set(j, list.get(j + 1));
list.set(j + 1, temp);
}
}
}

System.out.println(list);
}
}

No comments:

Post a Comment

Spring Boot - Bean LifeCycle

 Here is a clear, step-by-step lifecycle of a Spring Boot application , explained in a simple + interview-ready way. 🔄 Spring Boot Applica...

Kubernate