Hi ,
String[] arr = new String[3];
this allocate the size but all cell will contain null.
how can i initialize the string will 'a' or blank.
Tarun
Eric Sosman - 10 Jan 2008 13:02 GMT
> Hi ,
>
[quoted text clipped - 3 lines]
>
> how can i initialize the string will 'a' or blank.
arr[0] = "a";
arr[1] = " ";
arr[2] = "I hope this helps."
Alternatively,
String[] arr = { "a", " ", "I hope this helps." };

Signature
Eric Sosman
esosman@ieee-dot-org.invalid
Nigel Wade - 10 Jan 2008 13:03 GMT
> Hi ,
>
[quoted text clipped - 3 lines]
>
> how can i initialize the string will 'a' or blank.
The Java Tutorial is a good place to look for answers. This section covers
arrays, and initialization:
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html
Reading the entire tutorial would help you with the basics, and give you a much
better understanding of the language.
One answer to your question might be:
String[] arr = { "a", "", "something else"};

Signature
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
Lew - 10 Jan 2008 14:13 GMT
>> Hi ,
>>
[quoted text clipped - 14 lines]
>
> String[] arr = { "a", "", "something else"};
Also,
<http://java.sun.com/javase/6/docs/api/java/util/Arrays.html#fill(java.lang.Objec
t[],%20java.lang.Object)>

Signature
Lew
Lord Zoltar - 10 Jan 2008 14:32 GMT
> Hi ,
>
[quoted text clipped - 5 lines]
>
> Tarun
Perhaps you want:
String[] arr = new String[3];
Arrays.fill(arr,'a');
I know this works on char[], I've never tried it with String[] but I
think there's an overload for Object[]. Give it a shot! ;)
Roedy Green - 10 Jan 2008 14:50 GMT
>String[] arr = new String[3];
>
>this allocate the size but all cell will contain null.
>
>how can i initialize the string will 'a' or blank.
see http://mindprod.com/jgloss/array.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Chase Preuninger - 11 Jan 2008 00:18 GMT
Loop through every value, and set it how you want it.
Garg - 11 Jan 2008 04:17 GMT
thanks for the help.
what i am doing is
String[] arr;
String str = "Tarun|garg";
arr = str.split("\\|");
now this will split the str and arr will contain two values.
what i need to do is i have to fix the array like 10 and rest 8 fields
of the array should contain ''.
Garg
RedGrittyBrick - 11 Jan 2008 12:18 GMT
> thanks for the help.
>
[quoted text clipped - 8 lines]
> what i need to do is i have to fix the array like 10 and rest 8 fields
> of the array should contain ''.
Eric already answered this, didn't you read his reply?
String[] foo = { "Tarug", "Garg", "", "", "", "", "", "", "", "" };
or (easier to apply to larger arrays)
String[] foo = new String[10];
foo[0] = "Tarug";
foo[1] = "Garg";
for (int i=2; i< foo.length; i++) foo[i] = "";
or maybe (untested)
String[] foo = "Tarug|Garg||||||||".split("\\|");