File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes splitting arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "splitting arrays" Watch "splitting arrays" New topic
Author

splitting arrays

Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
hi

i have an array of strings and i want to split the string in each index and place it in a two dimensional array

strings are split using the .split("delimeter"); method

i would just like to know what the equivalent method for that is

thanks
Joni Salonen
Ranch Hand

Joined: Jan 07, 2006
Posts: 53
There is no method; you need to write a loop.
http://java.sun.com/docs/books/tutorial/java/data/arraybasics.html
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

The equivalent for what ?
There is a split() method in the String class.


[My Blog]
All roads lead to JavaRanch
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
how then do you split the values inside the array?
like for example in array[0], i have the String "1,D1254H35,x,MS,FOL"
and i want to split those separated by a comma it into diffent entries?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

split() returns a array of strings (String[])
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
split works for splitting strings

i want to split strings in an ARRAY.

also, another question.

in two dimensional arrays,can i populate the rows first, and then the columns much later? how is that done?
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296

split works for splitting strings

i want to split strings in an ARRAY.


How about:

[ February 20, 2006: Message edited by: Garrett Rowe ]

Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296

[ February 20, 2006: Message edited by: Garrett Rowe ]
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
Originally posted by Garrett Rowe:


[ February 20, 2006: Message edited by: Garrett Rowe ]



thanks a lot.
i'll try that one. i'll try to understand it first though

is that how a twodimensional array is populated?
coz i want to populate the 5 rows first, and after 5 values are put in, i then want to populate the inner array. the sizes are constant by the way.
i mean the twod array is

String[][] twoD = new String[20][10];

thanks
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
Originally posted by Garrett Rowe:


[ February 20, 2006: Message edited by: Garrett Rowe ]


it doesn't work
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
to populate the twoD array, this is what i did and it doesn't work
what is wrong with what i'm doing?

String [ ][ ] entryfields = new String[entlen][10];
for(int g=0; g<entlen; g++)
{
entryfields[g][0] = entry[g];
out.print(entryfields[g][0]);
}
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
Originally posted by shuini gustav:


[ February 20, 2006: Message edited by: Garrett Rowe ]<hr></blockquote>

it doesn't work[/QB]


It works. How are you using it?
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
thank you very much
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: splitting arrays
 
Similar Threads
Parsing out names from String
Collections API
String splitting & tokenizing problem
split() method
Idea to sort a list and get a result