3 Replies - 284 Views - Last Post: 14 August 2012 - 04:14 PM Rate Topic: -----

#1 RCharles  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 27
  • Joined: 12-August 12

How to assign the value of array from a class to another class?

Posted 14 August 2012 - 11:31 AM

How do you pass the value of inputs[i] to the getPivot function?

from this code:
  private void Splitter(){
           //Use split method to put the String into String array separated with " " delimeter
           String inputString = inputsjTextField.getText();
           String[] stringParts = inputString.split(" ");
          
           //Convert String array to int array
           int[] inputs = new int[stringParts.length];
           for (int i=0; i < stringParts.length; i++) {
               inputs[i] = Integer.parseInt(stringParts[i]);
               //System.out.println(inputs[i]);
           }
    }

      private void getPivot(){


}


Since i will use splitter on future parts of every sorting algorithm i will do. i decided to have it in one function. So the problem now, is how can i get the values of inputs[i] and put it on any variable in function getPivot.

This post has been edited by smohd: 14 August 2012 - 11:47 AM
Reason for edit:: Code tags added. Please use [code] tags when posting codes


Is This A Good Question/Topic? 0
  • +

Replies To: How to assign the value of array from a class to another class?

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2017
  • View blog
  • Posts: 3,046
  • Joined: 21-June 11

Re: How to assign the value of array from a class to another class?

Posted 14 August 2012 - 11:41 AM

Change Splitter's signature so that it returns an array rather than nothing. Then simply return inputs at the end of the method. In the getPivot method simply use the return value from Splitter as you would any other method's return value.

This post has been edited by sepp2k: 14 August 2012 - 11:41 AM

Was This Post Helpful? 0
  • +
  • -

#3 SPorter  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 31
  • Joined: 29-June 12

Re: How to assign the value of array from a class to another class?

Posted 14 August 2012 - 12:20 PM

Do you specifically want the input[i] of whatever i equals at that time to be passed to getPivot, or the whole array?

If the whole array, listen to what sepp2k said, if it's what I said first, then you just have to make getPivot accept int's then call it in your loop.
Was This Post Helpful? 0
  • +
  • -

#4 RCharles  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 27
  • Joined: 12-August 12

Re: How to assign the value of array from a class to another class?

Posted 14 August 2012 - 04:14 PM

@sepp2k

can you post a sample code from what i posted. please. so I can better understand.
(im a bgnner, sorry for this)

@SPorter

I wanted to get all the array values of inputs[i]
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1