-4
String decodedChecksum="A01046085|T98494055e|1200|2020-05-31T06:12:46.365Z"
String[] splitArray = decodedChecksum.split("|");
/* here i want to set values to getter setter*/
{
sample.setAppNo(A01046085)
sample.setId(T98494055e)
 ..
}

Please provide solution to iterate the array and set valuease to varibale

  • The question was not just how to split a string based on "|" but also how the resulting array can be processed to invoke different setters based on current index. IMHO, this is low level design problem that should have been answered. – Amar Dev May 31 '20 at 11:47

2 Answers2

0

It heavily depends on how your code is structured. If you're 100% sure of the structure of that string, it's as easy as:

String decodedChecksum="A01046085|T98494055e|1200|2020-05-31T06:12:46.365Z"
String[] splitArray = decodedChecksum.split("\\|");

sample.setAppNo(splitArray[0]);
sample.setId(splitArray[1]);
...
Balastrong
  • 4,336
  • 2
  • 12
  • 31
0

You need to escape the | because it's a special symbol in regex.

String decodedChecksum="A01046085|T98494055e|1200|2020-05-31T06:12:46.365Z";
String[] splitArray = decodedChecksum.split("\\|");

sample.setAppNo(splitArray[0]); // splitArray[0] = A01046085
sample.setId(splitArray[1]);    // splitArray[0] = T98494055e
...
b.GHILAS
  • 2,273
  • 1
  • 8
  • 16