0

I have this method written up, but not sure why I'm getting errors. I'm still pretty new to programming, so does anyone see anything blatenly wrong with this?

public String[] gen() {
    String big = "A";
    String small = "a";
    return String[] {big, small};   
}

Note: Getting a redline under return String[]

4
  • 4
    return new String[] {big, small}; Commented Oct 18, 2012 at 7:26
  • if you print the error you get, it will help us. anyway @Vincenzo response is the correct one. Commented Oct 18, 2012 at 7:27
  • 6 answers in like 20 seconds. What have I done. Commented Oct 18, 2012 at 7:28
  • but you still haven't accepted any of those answers Commented Oct 19, 2012 at 8:15

7 Answers 7

3

Change it to

public String[] gen() {

            String big = "A";
            String small = "a";
            return new String[] {big, small};

    }

String[]{String, String} //is not a valid array constructor,

instead you should use

new String[]{String, String} constructor.
Sign up to request clarification or add additional context in comments.

Comments

3

You are omitting the new keyword.

return new String[] {big, small};

Comments

1

You miss the keyword new

return new String[] {big, small};

Comments

0

Try

return new String[] {big, small};

Comments

0

Try this, you need to create string array using new keyword

public String[] gen() {

            String big = "A";
            String small = "a";
            return new String[] {big, small};

    }

Comments

0

You need to use new with array, use :

return new String[] {big, small};


public String[] gen() {    
        String big = "A";
        String small = "a";
        return new String[] {big, small};    
}

Comments

0
public String[] gen() {

        String big = "A";
        String small = "a";
        return new String[] {big, small};
    }

Use this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.