adding multiple entries to a HashMap at once in one statement

You can use the Double Brace Initialization as shown below: Map<String, Integer> hashMap = new HashMap<String, Integer>() {{ put(“One”, 1); put(“Two”, 2); put(“Three”, 3); }}; As a piece of warning, please refer to the thread Efficiency of Java “Double Brace Initialization” for the performance implications that it might have.

Best practice? – Array/Dictionary as a Core Data Entity Attribute [closed]

There is no “native” array or dictionary type in Core Data. You can store an NSArray or an NSDictionary as a transformable attribute. This will use the NSCoding to serialize the array or dictionary to an NSData attribute (and appropriately deserialize it upon access). The advantage of this approach is that it’s easy. The downside … Read more

Is there a way to iterate over a dictionary?

Yes, NSDictionary supports fast enumeration. With Objective-C 2.0, you can do this: // To print out all key-value pairs in the NSDictionary myDict for(id key in myDict) NSLog(@”key=%@ value=%@”, key, [myDict objectForKey:key]); The alternate method (which you have to use if you’re targeting Mac OS X pre-10.5, but you can still use on 10.5 and … Read more

for each loop in Objective-C for accessing NSMutable dictionary

for (NSString* key in xyz) { id value = xyz[key]; // do stuff } This works for every class that conforms to the NSFastEnumeration protocol (available on 10.5+ and iOS), though NSDictionary is one of the few collections which lets you enumerate keys instead of values. I suggest you read about fast enumeration in the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)