Sort String on CMD line w/o regards to case

The program should sort Strings on the command line without regard to case and print the following:

java Part4 Add a little SUGAR to your tea

will print

      a
      Add
      little
      SUGAR
      tea
      to
      your

I got it to sort but did not user the "ignoreUpperCase" method, can someone please assist on implementing the ignoreUpperCase method.

<code>

import java.util.*;
public class Part4
{
  public static void main(String args[])
  {
  List myList = new ArrayList(args.length);
  for (int i = 0; i < args.length; i++)
  {
   //System.out.println(i + ": " + args[i]);
   Arrays.sort(args);

  }
  for (int i = 0; i < args.length; i++)
   System.out.println(args[i]);

  }
  //public int compareTo(Object o)
  //{
 // return 0;
 //}
}
</code>

Thanks
Coconut77840Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sciuriwareCommented:
You can use the method  String.compareToIgnoreCase(String str)
Refer to the JAVADOC for String.
<*>
petmagdyCommented:
Vector ignoredCasesValues = new Vector();
  for (int i = 0; i < args.length; i++)
  {
     String ignoredValue = args[i].toString(0.toLowerCase();
   //System.out.println(i + ": " + args[i]);
  }
    Arrays.sort(ignoredCasesValues);
sciuriwareCommented:
it will be:

      Arrars.sort(args, new Comparator(Object a, Object b)
                                      {
                                             String sa = (String a);
                                             String sb = (String b);
                                             return(sa.compareToIgnoreCase(sb));
                                      }
                      );

<*>
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

sciuriwareCommented:
Just replace the old sort with mine.
<*>
sciuriwareCommented:
Sorry I forgot something:

      Arrars.sort(args, new Comparator()
                                      {
                                          public int compare(Object a, Object b)
                                           {
                                             String sa = (String a);
                                             String sb = (String b);
                                             return(sa.compareToIgnoreCase(sb));
                                           }
                                      }
                      );

<*>
sciuriwareCommented:
That should work.
Don't get confused by 'compare()'  <---->   'compareIoIgnoreCase()'
the latter can be anything.
<*>
petmagdyCommented:
sorry little correction:

Vector ignoredCasesValues = new Vector();
  for (int i = 0; i < args.length; i++)
  {
     String ignoredValue = args[i].toString(0.toLowerCase();
   //System.out.println(i + ": " + args[i]);
    ignoredCasesValues.add(ignoredValue);
  }
    Arrays.sort(ignoredCasesValues);

sciuriwareCommented:
petmagdy, your code destroys the strings.
The question was to sort, not to alter the case!
<*>
petmagdyCommented:
no sciuriware i keep the original as is in args[i]
petmagdyCommented:
oopps u r right sciuriware
sciuriwareCommented:
So you end up with 'args[]' that's not sorted and 'ignoredCasesValues' that is
sorted but lost uppercases.
What's the deal?
<*>
CEHJCommented:
Arrays.sort(args, String.CASE_INSENSITIVE_ORDER);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sciuriwareCommented:
Interesting, but this is not in the JAVADOC of 1.4 nor 1.5
<*>
sciuriwareCommented:
Indeed, I was looking at the class Arrays.

Well, Coconut77840, 2 good answers to your 125 points question.

You decide .........................................


<*>
Mick BarryJava DeveloperCommented:
>  for (int i = 0; i < args.length; i++)
>  {
>   //System.out.println(i + ": " + args[i]);
>   Arrays.sort(args);
>
>  }

you only need to call sort once, not once for every arg
the above can be replaced with

Arrays.sort(args, String.CASE_INSENSITIVE_ORDER);

CEHJCommented:
>>
the above can be replaced with

Arrays.sort(args, String.CASE_INSENSITIVE_ORDER);
>>

Please do not repeat comments that have already been made



Coconut77840Author Commented:
Would I have to add that Arrays.sort statement at the end of my current code?

Thanks guys
CEHJCommented:
After the first loop
Coconut77840Author Commented:
That made the trick.

Thanks
CEHJCommented:
8-)
Mick BarryJava DeveloperCommented:
> Please do not repeat comments that have already been made

Your comment was missing bits
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.