Results 1 to 3 of 3
  1. #1
    elektronika's Avatar
    elektronika is offline Member
    Join Date
    Dec 2009
    Location
    Indonesia
    Posts
    17
    Rep Power
    0

    Default Returning An Array

    Dear All,

    I am very new and fresh in Java. I want to make a class of matrices.

    What my code looks like:

    Matrix Class :
    Java Code:
    public class Matrix 
    {
    	private int[][] matrix;
    
    	public void CreateMatrix(int rows, int columns)
    	{
    		matrix = new int[rows][columns];
    	}
    	
    	public int[][] getMatrix() 
    	{
    		return matrix;
    	}
    	
    	public void setMatrix(int[][] matrix)
    	{
    		this.matrix = matrix;
    	}
    }
    My question is how to make a return type of Array (more than one return type?). In C I learn about pointer,,how about in java? The one I know until now is by making a array type variable also, then return it as an array also.

    For Example :
    int[][] arraycopy = matrixname.getMatrix();

    Kindest Regards
    Last edited by elektronika; 12-07-2009 at 04:34 PM.

  2. #2
    wtd_nielsen is offline Member
    Join Date
    Dec 2009
    Posts
    24
    Rep Power
    0

    Default

    more than one return type
    Do you mean different types like int[][], double[][], String[][] ?

  3. #3
    elektronika's Avatar
    elektronika is offline Member
    Join Date
    Dec 2009
    Location
    Indonesia
    Posts
    17
    Rep Power
    0

    Default

    Dear wtd_nielsen,

    what I mean by that is by returning for example 3 return integer type. What I know is in C is by using pointer. In Java how do I have 3 return integer type? The solution I have until now is by using the array type as the return.

    so for example :
    Java Code:
    public int[] getResults()
    {
         return int[] arrayresults;
    }
    and this is how I call it :
    Java Code:
    int[] wanttocall;
    ...
    ...
    ...
    wanttocall = getResults();
    And my question is :
    Is the method I use is good? Or there is any other method that is better?

    Kindest Regards,




    Elektronika

Similar Threads

  1. read() is not returning -1
    By Mewes in forum Networking
    Replies: 0
    Last Post: 11-30-2009, 11:46 PM
  2. Keeps returning null
    By ribbs2521 in forum New To Java
    Replies: 7
    Last Post: 02-23-2009, 03:25 AM
  3. Why is my list returning nothing?
    By xcallmejudasx in forum New To Java
    Replies: 2
    Last Post: 11-05-2008, 04:51 PM
  4. Returning array problem.
    By Chase in forum New To Java
    Replies: 4
    Last Post: 10-21-2008, 10:07 PM
  5. returning a value from an arraylist
    By xkross in forum New To Java
    Replies: 2
    Last Post: 04-18-2008, 06:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •