package com.comp; import java.util.Comparator; public class UserNameComparator implements Comparator{ public int compare(Object thisObject, Object comparedObject){ int retValue=0; String thisObjectUserName=((UserBean)thisObject).getUserName().toUpperCase(); String comparedObjectUserName=((UserBean)comparedObject).getUserName().toUpperCase(); if (!(thisObjectUserName.equals(comparedObjectUserName))){ //calling the compareTo method in String class retValue=(thisObjectUserName.compareTo(comparedObjectUserName)); } return retValue; } }