Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: hello.,i would like to create a method that accepts ...

  1. #1
    Member
    Join Date
    Nov 2010
    Posts
    40
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default hello.,i would like to create a method that accepts ...

    hello,
    i would like to create a method that accepts arrays as parameters and return an array as well, so,, please tell me whether the below stated java code is correct and if not, please guide me
    public static String [] convertStrToInt (String [] , String [] )
    {
    .....
    .....
    .....
    return ???
    }
    Last edited by helloworld922; November 20th, 2010 at 03:14 PM.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,659
    Thanks
    25
    Thanked 325 Times in 302 Posts

    Default Re: hello.,i would like to create a method that accepts ...

    public static String [] convertStrToInt (String [] , String [] )
    {
    .....
    .....
    .....
    return ???
    }

    A few things. First, the variables in your parameters need to be named:
    public static String [] convertStrToInt (String[] arr1 , String[] arr2 )
    {
    .....
    .....
    .....
    return ???
    }

    Second, based on your declaration, you need to return a String[]:
    public static String [] convertStrToInt (String[] arr1 , String[] arr2 )
    {
    .....
    .....
    .....
    //this is a basic return for a non-existent String[]
    return new String[0];
    }
    Last edited by aussiemcgr; November 20th, 2010 at 03:17 PM.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: hello.,i would like to create a method that accepts ...

    You need to declare the size of the string array, or you need to use an "in place" initializer

    return new String[0]; // array of size 0
    return new String[] {}; // array initialized to contain nothing

Similar Threads

  1. Can i call init() method in destroy method.?
    By muralidhar in forum Java Servlet
    Replies: 1
    Last Post: October 22nd, 2010, 11:18 AM
  2. How do i create Sub Form
    By hadhebola in forum Object Oriented Programming
    Replies: 1
    Last Post: July 16th, 2010, 08:21 AM
  3. How to create a new object of another class within a method
    By davie in forum Object Oriented Programming
    Replies: 1
    Last Post: April 16th, 2010, 05:53 PM
  4. How to create exe file
    By sirimalla in forum Java Theory & Questions
    Replies: 6
    Last Post: November 1st, 2009, 03:07 AM
  5. how to create exe jar
    By ttsdinesh in forum Java Theory & Questions
    Replies: 1
    Last Post: September 27th, 2009, 08:21 AM