ATOM
1430
CB
ASP
A
187
54.776
12.063
20.348

1.00
50.88
C


How do I store the above in bold into a 1x3 arrray after using StringSplit?

Recommended Answers

All 7 Replies

String.split() returns an array of Strings, and you know the indexes that you want to save (6-8). So there's at least one simple way to do it: make your new array of String[3] and walk through it, putting the first value in the first slot, the second value in the second slot, and the third in the third slot.

Now if you're doing this more than once, you should make it a method. Something like

private String[] subArray(String[], int startIndex, int endIndex)
{
  // your code in here
  //return the sub-array
}

Then you're writing modular code.

Please make the question clear.
The records are in seperate line and you want to store three bold strings in a 1by3 array. So why to use StringSplit?

Yeah, Java Programmer. I just realized I've got to use String Tokenizer.. Gosh.

If this is the same problem you were posting about earlier in the week, split will work just fine. You've got a line - a String - and you want it broken into parts. The main difference is that with the tokenizer, you've got to step through the parts one by one, probably in a for loop until you get to the parts you want. With split, you get an array and you can just grab the bits that you need.
Either will work, but I think you were right the first time.

But can I store part of the results into an array?

Because that part is crucial. I want to store it like this: {54.776 12.063 20.348}

As I said:

there's at least one simple way to do it: make your new array of String[3] and walk through it, putting the first value in the first slot, the second value in the second slot, and the third in the third slot.

Alright, I shall try it out! Thank you everybody for your help! :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.