简体   繁体   English

Java从Object []获取特定元素

[英]Java get specific element from Object[]

How can I print the second element from the below Object[] args ? 如何从下面的Object[] args打印第二个元素? Is there a way to get it using Arrays.toString(args) . 有没有办法使用Arrays.toString(args)来获得它。 I want to get only the 2nd element sayHello 我想只得到第二个元素sayHello

[com.example:type=Hello, sayHello, [Ljava.lang.Object;@1503f191, [Ljava.lang.String;@6229b4c0]

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 数组也是可以通过索引操作的对象,这些索引是指向其在对象中位置的整数,而且它们基于零,这意味着第一个元素位于索引0处

在此处输入图片说明

following the illustration above, what you need is to do Object foo = args[1]; 按照上面的说明,您需要做的是Object foo = args[1];

or invoke directly a method if required, eg args[1].toString(); 或在需要时直接调用方法,例如args[1].toString();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM