Home TechnologyProgrammingJava Subscribe to RSS

How Can I Use An Array Created In One Method In Any Other Method Or Class?

Answer Question

1 Answer - Sort by: Date | Rating

    Pass it to the next method, ensure the method being passed to has the correct parameters.

    Ie

    void CreateArray()
    {
      int[] intArray = {1,3,2,4,3,5}; //Create the array
      DoStuffWithArray(intArray); // pass intArray to DoStuffWithArray
    }

    // other method within class
    void DoStuffWithArray(int[] array)
    {
        print (array[0]); //print first element of the array passed to this method
    }


    0 0

    Mikesuttie 

    answered 7 months ago

      More

      More

         
         

        Ask a Question via Twitter

        Send a question to @askblurtit and we will publish it online and send you a reply everytime you receive an answer.

        Blurtit Store

        Get T-shirts, hoodies, caps and more at the Blurtit store

        Blurtit International