0

I am trying to loop through an array of objects but when trying to print it all I see is something like this

com.company.resources.datastructures.Preference@7db93e1a

I am converting an Oracle Cursor into this array of objects and it looks fine in the REST service response.

[
   {
      "preferenceId": "1",
      "preferenceValue": "N",
   },
   {
      "preferenceId": "2",
      "preferenceValue": "Y",
   }, 
   {
      "preferenceId": "3",
      "preferenceValue": "N"
   }
]

however I don't know how to properly iterate through this array of objects in Java.

Say preferencesFromCursor already coverted the cursor into array of objects.

Preference[] preferences = preferencesFromCursor;

  for(Preference p : preferences) {
      System.out.println("p.toString() = " + p.toString());
  }

My expected result is to replace each preferenceValue in the objects from "N" to false and "Y" to true.

I can't even properly output the object so I'm not even progressing with the conversion.

Should it look like this?

if(p.getPreferenceValue() == "Y") {
   p.setPreferenceValue(true) 
} else {
   p.setPreferenceValue(false)
}
LazioTibijczyk
  • 1,701
  • 21
  • 48
  • How would I replace the values though? if(p.getPreferenceValue() == "Y") { p.setPreferenceValue(true) } else { p.setPreferenceValue(false) } ? – LazioTibijczyk Nov 01 '18 at 10:36
  • About your last comment : not sure, but anyway I think you should not compare to a string using `==` in Java, but with `.Equals` – Pac0 Nov 01 '18 at 15:10

0 Answers0