Sort the character arrays insensitive in java

As you are looking for a case insensitive sort, it is like a custom sort where you can use a Comparator.
You need to convert the String to char[].
Pass it to Arrays.sort(array,comparator);
Please check if this works.

Here is the code
public class ArrayCheck {

public static void main(String[] args) {
	String str="World";
	char[] charArray = str.toCharArray();
	Character[] temp=new Character[charArray.length];
	for(int pos=0;pos<charArray.length;pos++){
		temp[pos]=charArray[pos];
	}
	CaseInsesitive caseI=new CaseInsesitive();
	Arrays.sort(temp,caseI);
	System.out.println(Arrays.toString(temp));
	
}

}
class CaseInsesitive implements Comparator{

@Override
public int compare(Character o1, Character o2) {
	return String.valueOf(o1).toLowerCase().compareTo(String.valueOf(02).toLowerCase());
}

}

Any constraints? Which complexity algo you want? O(N^2)? O(NlogN)?

No constraints.

By Append, do you mean adding at end or mixing them? Because I feel that for a string “bAdC” he wants it as “AbCd”. Meaning alphabets sorted irrespective of case.

does he want bdAC or as you stated, AbCd? He doesn’t explain that. :
If it is like yours I can use the concept of merge sort while appending sorted strings. Yup appendingg means adding at the end.

I feel he wanted AbCd. I think you should also provide that solution (who knows, might help some1 else XD)

is it possible to use sort function?

yup u can use sort function

1 Like

10W8TD - Online C++0x Compiler & Debugging Tool - Ideone.com it is the link to the way vijju stated

check my implementation it is simpler!

I wasn’t using merge sort though it can be solved using merge sort, check the code probably you’ll get it. I just modified the sort function.

I cant find your code ? :expressionless:

Can you check it in ideone.com

check the link i commented

Lol. 8 seconds difference b/w you giving link and him asking later.

1 Like

Please write code in java.

understand the code and write that yourself, you’ll learn better

@techbuzz nice approach!!