472,353 Members | 1,054 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

How to create an array?

Well, not exactly, bu tclose to that.
I whish to call a method that has, say, String[] as
an argument. Now, i haven't been in touch with Java
in a while so i don't remember the syntax. When i go:

object.method (new String ["a", "b"]);

the compiler naggs about missing "]". How do i create an
array without explicitly assigning a variable name to it?

--

Vänligen
Konrad
---------------------------------------------------
phone #1: (+46/0) 708 - 70 73 92
phone #2: (+46/0) 704 - 79 96 95
url: http://konrads.webbsida.com
e-mail: ch************@bigfoot.com
-----------------------------------

Sleep - thing used by ineffective people
as a substitute for coffee

Ambition - a poor excuse for not having
enough sence to be lazy
---------------------------------------------------

Jul 17 '05 #1
3 30575
Konrad Den Ende <ch************@bigfoot.com> wrote:
Well, not exactly, bu tclose to that.
I whish to call a method that has, say, String[] as
an argument. Now, i haven't been in touch with Java
in a while so i don't remember the syntax. When i go:

object.method (new String ["a", "b"]);

the compiler naggs about missing "]". How do i create an
array without explicitly assigning a variable name to it?


give this a try ...

String[] myArray = new String[] { "foo", "bar" };

Sample program :

class qwer {
public static void main( String[] args ) {
String[] myArray = new String[] { "foo", "bar" };
for ( int i = 0; i < myArray.length; i++ )
System.out.println( myArray[ i ] );
}
}

--
If you live in a country run by committee, be on the committee.
-- Graham Summer
Jul 17 '05 #2
SJ
Konrad Den Ende wrote:
Well, not exactly, bu tclose to that.
I whish to call a method that has, say, String[] as
an argument. Now, i haven't been in touch with Java
in a while so i don't remember the syntax. When i go:

object.method (new String ["a", "b"]);

the compiler naggs about missing "]". How do i create an
array without explicitly assigning a variable name to it?


object.method (new String[] {"a", "b"});
Jul 17 '05 #3
Hello Konrad,

try this:
public class Test
{
private static String foo( String[] test )
{
StringBuffer sb = new StringBuffer();

for( int i = 0; i < test.length; i++ )
{
sb.append( test[ i ] + ", " );
}

return sb.toString();
}

public static void main(String[] args)
{
System.out.println( foo( new String[] { "test1", "test2" } ) );
}
}
Best Regards
Silke
"Konrad Den Ende" <ch************@bigfoot.com> wrote in message news:<be**********@news.gu.se>...
String[] myArray = new String[] { "foo", "bar" };
System.out.println( myArray[ i ] );


How is that "create an array without explicitly assigning a
variable name to it"?

Vänligen
Konrad
---------------------------------------------------
phone #1: (+46/0) 708 - 70 73 92
phone #2: (+46/0) 704 - 79 96 95
url: http://konrads.webbsida.com
e-mail: ch************@bigfoot.com
-----------------------------------

Sleep - thing used by ineffective people
as a substitute for coffee

Ambition - a poor excuse for not having
enough sence to be lazy
---------------------------------------------------

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an...
5
by: Mountain Bikn' Guy | last post by:
How would I do this? public sealed class UtilityClass { public static MyObject Object1;//see note below about importance of static object names...
4
by: Bill Sun | last post by:
Hi, All I have a conventional question, How to create a 3 dimension array by C language. I see some declare like this: int *** array; int...
5
by: Richard Lewis Haggard | last post by:
I am trying to create multi-dimensioned arrays in conventional ASP pages and pass these arrays as arguments to functions that are in a C# interop...
1
by: dadevil | last post by:
Hi guys, this is my first post around here, and here it goes I need to create an array to store info about a number "n" of persons, so i create...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory...
1
geo039
by: geo039 | last post by:
Okay I have an application, which is to demonstrate the use of a created class. I have a previous and next button which cycles through the array....
10
by: SM | last post by:
Hello I'm trying to create a multi dimensional array in JavaScript, but after some reading i still can't figure out how to apply it to my model. ...
3
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the...
3
by: David K in San Jose | last post by:
I'm using managed (CLR) C++ in VS2005 to create a Windows app that contains a form named "MyForm". In the code for that form I'm trying to invoke...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.