0

How can I print the second element from the below Object[] args? Is there a way to get it using Arrays.toString(args). I want to get only the 2nd element sayHello

[com.example:type=Hello, sayHello, [Ljava.lang.Object;@1503f191, [Ljava.lang.String;@6229b4c0]
2
  • 1
    args[1] is going to do that... java arrays are zero indexed Commented Apr 24, 2017 at 6:18
  • System.out.println(args[1].toString()); or something like that. Commented Apr 24, 2017 at 6:24

1 Answer 1

3

Arrays are objects that can be manipulated by indices too, those indices are integers pointing to its location in the object, furthermore, they are zero based, which means, the 1st element is located at index 0

enter image description here

following the illustration above, what you need is to do Object foo = args[1];

or invoke directly a method if required, e.g. args[1].toString();

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.