我们如何在数组对象的帮助下调用方法?

问题描述 投票:-5回答:1

我们怎样才能在数组对象的帮助下调用这些方法?

例如 :

class Employee
    {
        int value;

        Employee(int value)
        {
            this.value = value;
        }

        public void checkValue(int value1, int value2)
        {
            // i want to check here value1 & value2 is there or not in array
            // Or in another word I want to retrieve every element of the array in this method.   
        }
    }

    public class Test
    {
        public static void main(String arg[])
        {
            Employee e1[] = { new Employee(100), new Employee(200), new Employee(300) };

            e1.checkValue(100, 200);

        }
    }

因此,在调用e1.checkValue(100,200)时,我收到编译时错误,我只想这样调用。这个问题在一次采访中问我。

java arrays
1个回答
0
投票

Arrays.stream(你的数组)将提供一个流。在流上应用带有ur输入的过滤方法然后使用收集器收集结果。

这应该是Java 8中的最新进展。

© www.soinside.com 2019 - 2024. All rights reserved.