aspose file tools
The moose likes Beginning Java and the fly likes string array declaration Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "string array declaration" Watch "string array declaration" New topic
Author

string array declaration

Jay X Brown
Ranch Hand

Joined: Jan 26, 2001
Posts: 51
why am i getting this error?
> testParser.java:11: Array dimension missing.
> static public String[] CName=new String[];
if i change it to:
static public String[] CName=new String[8];
it accepts it. but i don't want to do that. i don't know how long the string array is going to be. it depends on data.
thanks in advance
jb
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
> testParser.java:11: Array dimension missing.
> static public String[] CName=new String[];
when you try to define it like this you don't give a dimension size which is not allowed. You must provide size or do it like this
String []s = new String[]{"yes"};


Val SCJP <BR>going for SCJD
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Jay,
In Java array size is set at compile time and can't be changed at any other time. If you want to use something that is sizeable try using a vector. Once you get the total vector you can use the toArray() method to get the contents into an array.
Manfred.
Jay X Brown
Ranch Hand

Joined: Jan 26, 2001
Posts: 51
thanks val,
it compiled without problem. but what does this do?
> String []s = new String[]{"yes"};

and thanks for the vector suggestion. i now realize that is another route to go.
jay
ryan burgdorfer
Ranch Hand

Joined: Jan 24, 2001
Posts: 219
it specifies what is in the array...in this case, one string - "yes"
I think you may find that this is not going to be the ultimate solution in your case, since you said above that the size of the array depends on your data. In this case, your array has a size of 1...


<UL TYPE=SQUARE><I><LI>Ryan Burgdorfer<BR><LI>Java Acolyte</I></UL>
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: string array declaration
 
Similar Threads
getting instance of a class
Enumeration interface
Attribute Setting failed
why not we define a static member function inside a main
Regex - Java or Perl