Advertisement
salahzar

example of hashmap for byte[] keys

Feb 1st, 2016
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.84 KB | None | 0 0
  1. /**
  2.  * Created by pakkio on 01/02/2016.
  3.  */
  4. public class Main {
  5.     static HashMap<Object,Object>map=new HashMap<Object, Object>();
  6.     public static void main(String[] args) {
  7.  
  8.         byte[] b1=new byte[]{ 1,2,3};
  9.         byte[] b2=new byte[]{ 1,2,3};
  10.  
  11.  
  12.  
  13.         insert(b1,"value1");
  14.         remove(b1);
  15.  
  16.         insert(b1,"value2");
  17.         remove(b2);
  18.  
  19.  
  20.         System.out.println(map.size()+ " should be 0");
  21.     }
  22.  
  23.     private static void remove(Object input) {
  24.         map.remove(convert(input));
  25.     }
  26.  
  27.     private static void insert(Object input, Object value) {
  28.         map.put(convert(input),value);
  29.     }
  30.  
  31.     private static Object convert(Object input){
  32.         //if(true) return input;
  33.         if(input instanceof byte[]){
  34.             return new String((byte[])input);
  35.         }
  36.         return input;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement