There is a hashmap, which consists of a string and an object. Line = name. Object = properties. I can not understand how you can pull values ​​from an object if it has more than one property. The size () or lenght () method does not work for an object. Please help.

HashMap<String, Object> newPost = (HashMap<String, Object>) snapshot.getValue(); 

enter image description here

  • Object can not be replaced by a more specific implementation due to the nature of the project? - Bleser
  • The service gives me this data (I would love to - Ivan Vovk

1 answer 1

 System.out.println("Вот Ваши свойства"); foreach (Map.Entry<String, Object> s : snapshots.entrySet()) { System.out.println(s.getKey() + ":"); Map<Object, Object> properties = (Map<Object, Object>)s.getValue(); foreach (Map.Entry<Object, Object> p : properties.entrySet()) { System.out.println(" " + p.getKey() + ": " + p.getValue()); } System.out.println(" Итого " + properties.size() + " свойств(а)"); } 
  • Thank! It turned out to take properties, very grateful! - Ivan Vovk
  • And maybe tell me how to get out of this list, for example, the second property and the 4th? And the rest do not touch. - Ivan Vovk
  • one
    Values ​​are not pulled out of the hashes, not by the sequence number (because the concept of order is not defined there in principle), but by the key. If you need an ID and PREVIEW_TEXT_TYPE, then write p.get ("ID") and p.get ("PREVIEW_TEXT_TYPE"); - Sergey
  • one
    Even better, then you can let go of the second foreach! Thanks for the help! - Ivan Vovk