package com.javainhouse;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
public class findSmallestSubstring
{
public static void main(String[] args) {
String test="i am rajesh kumar attapattu";
String stest=test.substring(test.indexOf("a")+1, test.lastIndexOf("a"));
System.out.println(stest);
String arr[]=stest.split("a");
String smallestsubString=arr[0];
int minimumLength=arr[0].length();
for (int i = 0; i < arr.length; i++) {
if(arr[i].length() < minimumLength)
{
minimumLength=arr[i].length();
smallestsubString=arr[i];
}
}
System.out.println("Smallest string between a is "+smallestsubString);
}
}
|
Smallest SubString |
Post a Comment