0

I have API response like below

"Name","Product ID","Product Description","Location", "Product Family","Product Type","Serial Number"
"W2DY-BL3I-AR7Z","ABC67-HW","Security Appliance","USA", "Cloud Managed Security Appliances","Security","Q2AY-YX3W-VRXZ"

First line is CSV headers & second line is values.

I want to get values of Product ID, Location & Serial Number like below:

ABC67-HW
USA
Q2AY-YX3W-VRXZ
Neuron
  • 5,141
  • 5
  • 38
  • 59
Garry S
  • 85
  • 1
  • 9
  • 1
    Does this answer your question? [CSV API for Java](https://stackoverflow.com/questions/101100/csv-api-for-java) – Joe Sep 15 '21 at 06:03

1 Answers1

-1

Take both the first line and second line into ArrayList.

let's say headers ArrayList

let's say values ArrayList

int index = headers.get("Product ID");
if (index >= 0){
    String productId = values.get(index);
}

and keep reading the other headers also exactly the same way and keep obtaing their respcting values.

  • how to take lines into arraylist? any suggestions? i got both lines in 1 single variable. like: String exportDataReceived = somefunction(apiURL); exportDataReceived contains both lines. – Garry S Sep 15 '21 at 05:54
  • Split the exportDataReceived by "\n" a new line separator. Now you would have two strings in an array, the first one is CSV headers, and the second one being their corresponding vlaues. You can keep on tokenizing from there on. Many thanks! – Vijay Kambala Sep 27 '21 at 10:41
  • eg: String headers = exportDataReceived.split("\n")[0]; String values = exportDataReceived.split("\n")[1] – Vijay Kambala Sep 27 '21 at 10:47