Java – How to split a concatenated string into multiple floating point values

corejava

I'm a begginer in java I have

packet=090209153038020734.0090209153039020734.0 

like this I want to split this string and store into an array like two strings:

1) 090209153038020734.0
2) 090209153039020734.0

I have done like this:

String packetArray[] = packets.split(packets,Constants.SF); 

Where:
Constants.SF=0x01.

But it won't work.

Please help me.

Best Solution

I'd think twice about using split since those are obviously fixed width fields.

I've seen them before on another question here (several in fact so I'm guessing this may be homework (or a popular data collection device :-)) and it's plain that the protocol is:

  • STX (0x01).
  • 0x0f.
  • date (YYMMDD or DDMMYY).
  • time (HHMMSS).
  • 0x02.
  • value (XXXXXX.X).
  • 0x03.
  • 0x04.

And, given that they're fixed width, you should probably just use substrings to get the information out.