Hi all, Can anybody tell me how to construct arrays of strings from a vector dynamically? I have a vector which has data in this form. /aaa /bbb /ccc are the indicators and the data follows them. /aaa xxx xxx xxx xxx xxx xxx /bbb xxx xxx xxx /ccc .... /ccc ... I want to dynamically shift /aaa contents into a separate array (say aaa). Similarly /bbb strings into bbb array. There is only one element (/ccc) which can repeat multiple times. In such a case how do we construct multiple arrays? Thanks in advance.
Sounds like this is a bit too complex to do in one step. The basic problem is that for an array, you really need to know how many elements there are before you create the array. (Or you can write code to resize the array automatically, but that's more complex, and that's what ArrayList does anyway, so why reinvent the wheel?) I would recommed that you first create several different ArrayLists, one for each array you plan to have eventually. E.g. aList, bList, cList... Then loop through the initial ArrayList to look at eack element and decide which of the other lists that line should be copied to. At this stage, you don't know how many elements will go in a, b, c, etc., so it's easier to just use ArrayLists while you're still deciding this. Then when you're done, you can convert each ArrayList to a String: