Sorting of name with upper case and lower case wise


Description:
Below example shows how to find out first upper case shorting next lower case shorting algorithms

Code 1:
?
package com.kartik;
/**
 * 
 * @author kartik 
 * sorting algorithm is an algorithm that puts elements of a list in a certain order
 * This sorting is Upper case wise first display and next display Lower case by index wise 
 */
public class StringDemo {

public static void main(String[] args) {
//String[] toppings = {"mandal","Cheese","veloCity","sumitra", "Pepperoni","mocha","aMerica", "kaRtik","javA"};
String[] toppings={"Ukraine", "united Arab Emirates", "United Kingdom", "United States",
"uruguay", "Uzbekistan", "Vanuatu", "Vatican City", "vietnam", "Venezuela",
"Wallis and Futuna", "Western Sahara", "Yemen", "Zambia", "Zimbabwe"};
SortingImplementation ss=new SortingImplementation();
ss.demString(toppings);

}

}

Code 2:
?
package com.kartik;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
 * 
 * @author kartik 
 * sorting algorithm is an algorithm that puts elements of a list in a certain order
 * This sorting is Upper case wise first display and next display Lower case by index wise 
 */
public class SortingImplementation {

ArrayList<String> countrylist= new ArrayList<String>();
public void demString(String[] countryArray){
Arrays.sort(countryArray);
 countrylist= new ArrayList<String>(Arrays.asList(countryArray));
List<String> tempCountryList=new ArrayList<String>();
int maxStringLength=0;
int tempStringLength=0;
int tempIndex=0;
int indexOfString=0;
//find out max length of string
for (String country : countrylist) {
tempStringLength=country.length();
if(tempStringLength>maxStringLength){
maxStringLength=tempStringLength;
}
}
//add upper case string to tempCountryList
for(int count=0;count<countrylist.size();count++){
for (String country : countrylist) {
if(country.length()<=maxStringLength){
indexOfString=tempIndex;
if(country.length()>indexOfString){
if(Character.isUpperCase(country.charAt(indexOfString))){
if(!tempCountryList.contains(country)){
tempCountryList.add(country);
tempIndex=indexOfString;
}
  }
}
}
}
tempIndex++;
}
//add not upper case string to tempCountryList
tempIndex=0;
indexOfString=0;
for(int count=0;count<countrylist.size();count++){
for (String country : countrylist) {
if(country.length()<=maxStringLength){
indexOfString=tempIndex;
if(country.length()>indexOfString){
if(!Character.isUpperCase(country.charAt(indexOfString))){
if(!tempCountryList.contains(country)){
tempCountryList.add(country);
tempIndex=indexOfString;
}
  }
}
}
}
tempIndex++;
}
//display sorting string array list
for (String country : tempCountryList) {
System.out.println(country);
}
}
}


Output:
Ukraine
United Kingdom
United States
Uzbekistan
Vanuatu
Vatican City
Venezuela
Wallis and Futuna
Western Sahara
Yemen
Zambia
Zimbabwe
united Arab Emirates
uruguay
vietnam


Example:





Previous
Next Post »

2 comments

Click here for comments
Unknown
admin
27 April 2016 at 05:04 ×

great kartik , thank you very much on the solution you gave.

Reply
avatar
Unknown
admin
6 May 2016 at 06:57 ×

Kartik you passed the challenge.

Reply
avatar