dreamer
dreamer

Reputation: 69

Duplicating default behavior of Unix sort in Java

Linux sort uses en_US.UTF-8 by default.

I'm trying to find a Locale and Collator that will duplicate the way that Unix(Linux) sort works by default.

Does anyone have any ideas?

Thanks much.

sl73caeapp03:~ $ cat f

a

A

b

B

sl73caeapp03:~ $ sort f # how to duplicate this behavior?

a

A

b

B

sl73caeapp03:~ $ LC_ALL=C sort f # not this behavior

A

B

a

b

-dreamer

Upvotes: 1

Views: 191

Answers (1)

erickson
erickson

Reputation: 269797

Did you try Locale.US?

String[] test = { "A", "a", "B", "b" };
Collator order = Collator.getInstance(Locale.US);
Arrays.sort(test, order);
for (String s : test)
  System.out.println(s);

Upvotes: 1

Related Questions