3

I have a base64 encoded string and inserting it in a hashmap but the value stored in the hashmap is just 10% of the base64 string. While debugging, I can confirm that the string has the entire value. Only when I 'put' the string in the hashmap it stores only 10% of it.

Hashmap<String, String> hashmap = new Hashmap<>();
String base64 = bitmapToString(mBitmap); // function is working properly and Im getting the entire string.
hashmap.put("image", base64); // Storing just 1005 characters for every image

Is there any limit to hashmap values? Its always storing strings not more than 1005 characters. FYI this code is used in an IntentService

dhananjay dewan
  • 119
  • 2
  • 14
  • 2
    @Tilak Pointing someone at Google isn't helpful here – OneCricketeer Apr 21 '17 at 07:31
  • 3
    The map doesn't "store a string", it only keeps a reference to the original String. What you describe isn't possible ==> [mcve]. – assylias Apr 21 '17 at 07:31
  • 2
    The hashmap is not storing the String but only a String-reference, so I can't see any way it could somehow truncate it. How do you determine that there are only 1005 characters? – piet.t Apr 21 '17 at 07:32
  • 1
    @TilakMaddy Google doesn't provide any information about limitations in hashmap values. Most of them are related to hashmap size and character length of key. Nothing to do with value. – dhananjay dewan Apr 21 '17 at 07:32
  • @piet.t I copied the value in the hashmap while debugging and checked the char length. – dhananjay dewan Apr 21 '17 at 07:36
  • 1
    Could it be a limitation of your debugger, only showing the first characters of the string? – assylias Apr 21 '17 at 07:38
  • 1
    The special thing with Strings in Java is that they are immutable. The String cannot change under any condition, if the reference is valid. – kalsowerus Apr 21 '17 at 07:38
  • Please post some code demonstrating the problem. – shmosel Apr 21 '17 at 07:39
  • @dhananjaydewan There is no limitation like this – Ashraful Islam Apr 21 '17 at 07:40
  • Post a screenshot of the length of the string before mapping it and the length of the string from the hashmap.get() method – Denny Apr 21 '17 at 07:40
  • @assylias The debugger is showing the entire string when getting from the function. – dhananjay dewan Apr 21 '17 at 07:41
  • Pretty sure your debugger is doing some truncation when displaying the value - but we don't know what IDE/debugger you are using, how you display/copy the the values when displaying the String directly/the String from the map. – piet.t Apr 21 '17 at 07:49
  • @assylias You were right! When viewing hashmap with key and value it shows just a part of it. But when I checked the value alone it displayed the entire string. I'm using Android Studio. – dhananjay dewan Apr 21 '17 at 07:52

1 Answers1

2

It was a limitation(?) of the Android Studio debugger where it only shows around 1000 characters when viewing all keys and values but if you expand an element in the hashmap then it displays the whole string. It was complacency from my part and I thank @assylias for his advice.

dhananjay dewan
  • 119
  • 2
  • 14
  • 2
    I also faced similar issue few days back while sending the Base64 Data to a server. And at the server the string was indeed not full.So don't think its only debugger issue. – Deb Apr 21 '17 at 11:36