Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

splitting arrays

 
Bernard Sigmund Gustav
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no method; you need to write a loop.
http://java.sun.com/docs/books/tutorial/java/data/arraybasics.html
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The equivalent for what ?
There is a split() method in the String class.
 
Bernard Sigmund Gustav
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
split() returns a array of strings (String[])
 
Bernard Sigmund Gustav
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

split works for splitting strings

i want to split strings in an ARRAY.


How about:

[ February 20, 2006: Message edited by: Garrett Rowe ]
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[ February 20, 2006: Message edited by: Garrett Rowe ]
 
Bernard Sigmund Gustav
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Garrett Rowe:


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


it doesn't work
 
Bernard Sigmund Gustav
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic