Array as method argument

Is there anyway to pass an Array as argument without declare an array variable before?
Example:
public class MyClass
public MyClass
myMethod( HOW CAN I PASS AN ARRAY HERE !);
public void myMethod(String[] myArray)
// The method body ;

Is there anyway to pass an Array as argument without declare an array variable before?what's the point of passing the array then?
when you passs the array..you want to send some information and get someinformation back
by not decalring the variable before passing in the array..it's just makes no sense
mind as well rewrite the method to taks no argument
but here..you do it like this
myMethod(new String[]) // not initialized array of String
myMethod(null); // send in a null object

Similar Messages

  • Creating arrays in method argument

    this words fine
    int[] f = {1,2,3,4};but when i try make it into one line, for example for usage as arguments to a method, it does not compile
    class test {
         public static void a(int[] in) {};
         public static void main (String[] args) {
              a( (int[]) {1,2,3,4 } );
    };i know i could just declare the array before hand, but it in my case it involves calling a super constructor, which must be the first line in the function.
    help would be appreicated

    Hi,
    a(new int[] { 1,2,3,4,});
    /Kaj

  • Doubt in working of Arrays.sort method. help needed !!!!

    Hello Friends,
    I am not able to understand output of Arrays.sort method. Here is the detail of problem
    I wrote one program :
    public static void main(String[] args) throws ClassNotFoundException
         Object[] a = new Object[10];
         a[0] = new String("1");
         a[1] = new String("2");
         a[2] = new String("4");
         a[3] = new String("3");
         a[4] = new String("5");
         a[5] = new String("20");
         a[6] = new String("6");
         a[7] = new String("9");
         a[8] = new String("7");
         a[9] = new String("8");
    /* Sort entire array.*/
         Arrays.sort(a);
         for (int i = 0; i < a.length; i++)
         System.out.println(a);
    and output is :
    1
    2
    20
    3
    4
    5
    6
    7
    8
    9
    Question : Does this output is correct? If yes then on which basis api sort an array? I assume output should be 1 2 3 4 5 6 7 8 9 20.
    Can here any one please explain this?
    Thanks in advance.
    Regards,
    Rajesh Rathod

    jverd wrote:
    "20" and "3" are not numbers. They are strings, and "20" < "3" is exactly the same as "BA" < "C"The above is
    ... quote 20 quote less than quote 3 quote...
    but shows up as
    ... quote 20 quote less than quote...
    Weird.

  • Passing array as a argument in the Stored Procedure/Function

    Hello Friends,
    I need a help, i Want one stored proedure/Function which take array as a argument and return an array also.
    and the size of array should not be fixed.
    I don't want to use Varray because for this I have to specified its size first.
    I think Associative arry will work( For dynamic size) but I am not able to run it .
    Is Associative arry(Index by Pls_Integer) support JDBC?
    If yes, plz give me some clue. I have found some information of associative array in this url
    http://www.oracle.com/technology/oramag/oracle/07-jan/o17odp.html
    But I am not able to run this package through SQL and also not able to connect it through JDBC.
    Is there any other alternative solution?
    Thanks & Regards,
    manish Kumar

    This is my table structure :
    SQL> desc jobs
    Name Null? Type
    JOB_ID      NOT NULL VARCHAR2(10)
    JOB_TITLE      NOT NULL VARCHAR2(35)
    MIN_SALARY NUMBER(6)
    MAX_SALARY NUMBER(6)
    My Requirement is, User will enter the above field value in the form of array. I need to store these value and after manupulating this I will return that value also.
    Here I am using procedure just for testing purpuse.
    In my case I will take one array argumentlike JOB_ID and after manupulating these data I will return that array value.
    I am also not able to run this example through SQL.
    Can U give me exact code for running this prog.
    create or replace package associative_array as
    -- define an associative array type for each column in the jobs table
    type t_job_id is table of jobs.job_id%type index by pls_integer;
    type t_job_title is table of jobs.job_title%type index by pls_integer;
    type t_min_salary is table of jobs.min_salary%type index by pls_integer;
    type t_max_salary is table of jobs.max_salary%type index by pls_integer;
    -- define the procedure that will perform the array insert
    procedure array_insert (p_job_id in t_job_id,
    p_job_title in t_job_title,
    p_min_salary in t_min_salary,
    p_max_salary in t_max_salary);
    end associative_array;
    create or replace package body associative_array as
    -- implement the procedure that will perform the array insert
    procedure array_insert (p_job_id in t_job_id,
    p_job_title in t_job_title,
    p_min_salary in t_min_salary,
    p_max_salary in t_max_salary) is
    begin
    forall i in p_job_id.first..p_job_id.last
    insert into jobs (job_id,
    job_title,
    min_salary,
    max_salary)
    values (p_job_id(i),
    p_job_title(i),
    p_min_salary(i),
    p_max_salary(i));
    end array_insert;
    end associative_array;
    Regards,
    manish Kumar

  • Read only method arguments

    Can I make method arguments read only?? I want to send an object to a method and make it read only. i dont want a method to change public varables of the mthod argument object.
    Can anyone help me on this??
    Thanks,
    Vaijayanti

    Not possible, but you can pass a copy of the object, so that even if it's changed the changes aren't reflected to the original object.

  • Getting method arguments as hasmap

    Hi,
    can I get a method arguments in hashtable ? for example
    public void methodA(integer arg1,string arg2, integer arg3)
    so,
    is there any method in java that return a hashtable contains all method arguments , while running methodA.
    hashTable would be like this :
    arg1 1
    arg2 'a'
    arg3 5

    Bender_R. wrote:
    If you really need it, you can do it using Spring AOP. See AOP
    Edited by: Bender_R. on Oct 29, 2009 11:47 AMWhich won't give parameter names. And is unnecessary anyway, since you could just use a dynamic proxy without having to have all the Spring dependencies present

  • [svn:fx-trunk] 7825: Updating sample Java formatter for Eclipse projects to stop reformatting method arguments .

    Revision: 7825
    Author:   [email protected]
    Date:     2009-06-13 14:17:47 -0700 (Sat, 13 Jun 2009)
    Log Message:
    Updating sample Java formatter for Eclipse projects to stop reformatting method arguments.
    QA: No
    Doc: No
    Modified Paths:
        flex/sdk/trunk/development/eclipse/java/formatter.xml

    If you're still using Buckminster 3.6, I strongly suggest switching to 3.7 - it has a number of bug fixes and improvements. This applies to both headless, and the IDE (assuming Eclipse 3.7 Indigo).
    Matthew

  • Passing array as method to activex

    Dear Users;
    Sorry if this is a repeat question - I could not find relevant code in the faq.
    I have an activeX control which contains a method (PassArray) which accepts an array, and modifies its contents... The array *seems* to be correctly passed in, and I can make the modifications to the data. The data is then passed back out... In labview I use the Variant -> Data object to return the underlying dataset. However all my modifications are lost. (Sample code below).
    Ie: it seems Labview is passing me a copy of the original data, and does not accept that changes have occured. When I create a method which returns a variant containing a new array (ReturnArray), everything works properly. Does this occur because methods use 'const' keywords for parameters? Is there a solution where labview accepts that the data has changed?
    Any hints would be useful...
    thanks,
    Marc
    VARIANT CAcxLVArrayCtrl::ReturnArray(short Lendth)
    VARIANT vaResult;
    VariantInit(&vaResult);
    // TODO: Add your dispatch handler code here
    // Ok use this code to generate an array based upon size of Lendth.
    double* lpusBuffer;
    //Assigns the Variant to hold an array of doubles (real 8-byte numbers)
    vaResult.vt = VT_ARRAY | VT_R8;
    SAFEARRAYBOUND rgsabound[1];
    //Set bounds of array
    rgsabound[0].lLbound = 0; //Lower bound
    rgsabound[0].cElements = Lendth; //Number of elements
    //Create the safe array of doubles, with the specified bounds, and only 1 dimension
    vaResult.parray = SafeArrayCreate( VT_R8, 1, rgsabound );
    SafeArrayAllocData( vaResult.parray );
    SafeArrayAccessData( vaResult.parray, (void**)&lpusBuffer );
    //Fill in the buffer
    for( int i=0; i
    *(lpusBuffer + i ) = i + 1;
    SafeArrayUnaccessData( vaResult.parray );
    return vaResult;
    short CAcxLVArrayCtrl:assArray(const VARIANT FAR& ArrayInOut)
    // TODO: Add your dispatch handler code here
    long LowerBound, UpperBound, cbElements;
    if(ArrayInOut.vt != (VT_ARRAY | VT_I4))
    MessageBox("Data is not an array of Longs");
    return -1;
    if(SafeArrayGetDim(ArrayInOut.parray) != 1)
    MessageBox("Data must be a 1D array");
    return -1;
    SafeArrayGetLBound(ArrayInOut.parray, 1, &LowerBound);
    SafeArrayGetUBound(ArrayInOut.parray, 1, &UpperBound);
    if( (UpperBound - LowerBound) = 0)
    MessageBox("Data array is not initialised");
    return -1;
    long* lpusBuffer;
    SafeArrayAccessData( ArrayInOut.parray, (void**)&lpusBuffer );
    //Fill in the buffer
    for( int i=LowerBound; i
    *(lpusBuffer + i ) = i + 1;
    SafeArrayUnaccessData( ArrayInOut.parray );
    return 0;

    Fortunately I was able to determine what I was doing wrong. LabView and Visual Basic for Applications (VBA) only support the VARIANT data type for arrays. Visual Basic, however, supports more descriptive array parameter specifications in IDL. In other words, there are numerous valid ways to declare array parameters in IDL, however, some tools only support a subset. LV only supports VARIANTs. So in the previous IDL example:
    [id(3), helpstring("method NSEnumDevice")] HRESULT NSEnumDevice([in] int devIndex, [in] SAFEARRAY(int) *ports);
    becomes -
    [id(3), helpstring("method NSEnumDevice")] HRESULT NSEnumDevice([in] int devIndex, [in] VARIANT ports, [out, retval] VARIANT *devObj);
    Where devObj is an ActiveX wrapped object. VARIANT "ports" is an array of integer values. To specify returning an array of values, you still just use "[out, retval] VARIANT *array".
    --ddixon

  • Passing array via methods

    I am trying to enter x amount of marks by passing a method but placing in an array. When i compile i get no faults but method isn't passing. if i set a number it works but only to to that set number.
    Any help would be appreciated.
    import javax.swing.*;
    public class HomeWork8Week10
         public static void main(String args [])
              int mark = 0;
              getInt(mark);
              int size=0;
              getMarks(size);
         private static int getInt(int mark)
              String number = JOptionPane.showInputDialog(null,"Enter number of marks",
                                  "Homework 8",JOptionPane.QUESTION_MESSAGE);
              return Integer.parseInt(number);
         public static int[] getMarks(int size)
              int[] marks = new int[size];
              for(int i =0; i<marks.length; i++)
                   String numberOfMarks = JOptionPane.showInputDialog(null,"Enter mark",
                                  "Homework 8",JOptionPane.QUESTION_MESSAGE);
                   marks[i] = Integer.parseInt(numberOfMarks);
              return marks;
    }

    Right, and anticipating a possible questions, you'd code it like this:
    int[] results = getMarks(marks);
    Also, there seems not need to send the method getInt anything at all.

  • ADFBC Where to define labels for custom Application Module method arguments

    I was wondering if there was a "good place" to define these labels in ADF Business Components. I can just change them for the UI for my current project, but I thinking there might be a better way.
    Thanks,
    Brian

    Hi,
    I think you can't in BC, but you can in ADF. If you drag a method onto the client then it creates a method binding with argument itemes below. In addition, look in the executable section, it creates variables for each. This is where you can define labels so that they can be translated
    Frank

  • Accessing array content methods

    This is quite simple to do in C++ from what I remember but its got me stumped so far (it is getting late so maybe my brains slowing down).
    I simply want to access an object in my array and use its getValue() function to return the value of that object.
    Unfortunately I can't seem to do it at the moment.
    I presumed i'd be able to do something like MyArray.get(1).getValue.
    Basically im looking for the Java version of MyArray[1].getValue()
    Sorry to bother you with such a simple question but the search archive had posts focusing on accessing classes from other classes/packages.
    Thanks

    jverd,
    I haven't set my array to specifically store a
    specific object, however I know it always will.
    Are you suggesting there is a better way?Declare the type to be as specific as you can.
    If you're only sticking Foo objects in there, declare it as Foo[]. If you're sticking Foo and Bar objects in there, but the have a common superclass or implement a common interface Baz, then declare it as Baz[]. BUT only if you want to use the objects as Bazes. If you're going to have to cast it to Foo or to Bar because you want to access methods that only those classes have--that aren't in Baz--then you probably shouldn't be storing them in the same array.
    Storing a single type is also a good idea with Collections. However up through 1.4, you can't declare the type that the collection will hold. With 1.5, generics lets you do that.

  • Method argument names

    Hey, quick question, and unfortunately I think I know the answer. I'm no expert at using reflection, but from what I can tell thus far, it is possible to get the Class name, the names of the fields in the class, and the method names. I need the names of the arguments in the methods. i.e. as a simple example:    public double quotient(double dividend, double divisor) {
            return dividend/divisor;
        }I can get the method name, the return type and the types of the arguments, but I need the actual names of the arguments. In this case I would need "dividend" and "divisor". Is this possible, and if so please let me know how?
    Thanks,
    Steve

    This is not possible with 1.5. I heared some roumor that 1.6 will provide access to argument names.

  • Remote method arguments (RMI)

    Configuration:
    OC4J Release 2
    JDeveloper 9i RC
    Problem:
    I get a "ClassNotFoundException" when passing objects as arguments to a remote method.
    The object being passed implements an interface. The interface extends "Serializable" and it is available on the server (where the RMI class resides).
    Appreciate any help on this.
    Thanks,
    Ranga

    Found the solution. Thanx.

  • Quick Question on Arrays.fill() Method

    Does this work for a multidimensional array? I've tried and I can't get it to.
              double stuGrade[][];
              stuGrade = new double[3][125];
              Arrays.fill(stuGrade, -1); //Have also tried Arrays.fill(stuGrade[][], -1) error: Cannot resolve symbol
    symbol: method fill (double, int)
    Have imported java.util.Arrays....
    I need to set all values in atleast one row to a negative number. I haven't had a chance to look at vector (is that it?) arrays. So every element may not be populated. Since it is possible for an entry to be zero, I can't use a condition of not equal to zero to determine whether the loop should continue processing or not....
    Thank you!

    fill(double[] a, int fromIndex, int toIndex, double
    val)
    Where a is your array.... so really your just missing
    your fromIndex and toIndex... no worries.Seeing as how the OP's array is a double[][] rather than a double[], the worries will continue. The fromIndex and toIndex are optional; if he's wanting to fill a single entire array, the fill(double[] a, double val) is fine.

  • Covariant Method Arguments/Returntypes on abstract methods

    Hi all,
    can someone enlight me - please!
    is there a special reason, why i cannot use the new jdk 5 covariant arguments/returntype feature in conjunction with abstract methods???
    I cannot find a reason anywhere!
    I did something like this:
    public interface DAO {
      public boolean save(Base b);
      public Base read(Long id);
    public abstract class AbstractBaseDAO implements DAO {
      public abstract boolean save(Base b);
      public abstract Base read(Long id);
    public class PersonDAO extends AbstractBaseDAO {
      public boolean save(Person p) {
      public Person read(Long id) {
    Of course Person extends Base ...
    Any hints, etc. are welcome!
    kind regards
    K:)

    And if it does apply to args, won't it have to go the other way?
    That is, if the interface/parent class takes Person as an arg, then the subclass can take Base.
    The way you have it, the interface requires you to accept Base as an arg--ANY Base, but your subclass' save method requires a Person, so it won't work with a non-person base. The subclass isn't honoring its parent's contract. Covariance won't change that.

Maybe you are looking for