0

I'm writing a program that takes 3 or 5 arguments. The first is a String, the middle is/are numbers, and the last one is a String. However, the last argument is also surrounded by quotation marks, and needs to be treated as one string. This makes it impossible to use .split(), as I have tried.

For example: bob 1 2 3 "jimmy john" should be [bob, 1, 2, 3, jimmy john], not [bob, 1, 2, 3, jimmy, john]. Thanks!

goodcow
  • 3,465
  • 3
  • 28
  • 46

2 Answers2

4

You said "arguments," so you must mean command line arguments.

public static void main(final String[] arguments)
{
    Object[] myArray = new Object[arguments.length];

    for (int index = 0; index < arguments.length; ++index)
    {
        myArray = transformAsDesired(arguments[index]);
    }
}

implement transformAsDesired to convert numbers to Integers as desired. The argument "blammy blam" will show as one entry in the arguments array.

DwB
  • 33,855
  • 10
  • 50
  • 78
0

If this is a constructor taking in arguements then you should make the String at the end a variable before passing it through? So you would pass through (bob 1 2 3 variableName)