4

How do you manually assign variables to an array? I have a code fragment below. I don't want to manually put shortStraight[0] = "211100", shortStraight[1] = "021110", and so on. Any help?

private String [] shortStraight;

    public Sample () {
        shorty = new String [12];
                shorty = {211100, 021110, 002111, 121100, 112100, 111200, 012110, 011210, 011120, 001211, 001121, 001112 } //this line doesn't work.

Any help?

3
  • 2
    Vote to close, this is too dang easy (google - "java initialize array of strings") Commented Sep 27, 2011 at 18:56
  • Um....which one is it? Both your answers are different. Commented Sep 27, 2011 at 18:57
  • 1
    This is a legitimate question, even if in your opinion it's "too dang easy". Commented Sep 27, 2011 at 19:53

2 Answers 2

6
String[] shorty = {"211100", "021110", "002111", "121100", "112100", "111200", "012110", "011210", "011120", "001211", "001121", "001112"} ;
Sign up to request clarification or add additional context in comments.

Comments

6
String[]   shorty = {"211100", "021110", "002111", "121100", "112100", "111200", "012110", "011210", "011120", "001211", "001121", "001112"} ;

http://download.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

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.