Jun 11

Reducing the size of List in Java

I had a List that had around 70000 objects in it and I needed only the first 15000. I was about to create a new empty array list and iterate 15000 times over the current one in order to get a smaller list. That would have been a mess.

I searched a bit and realized there was an easier (and I’m hoping it’s more efficient) way to reduce the size of a list.

//templist has 70000 objects in it

tempList.subList(15000 – 1, tempList.size()-1).clear();

//templist now has the first 15000 objects in it

//15000 – 1 because the positions start from 0


Jun 11

Fetch Multiple Objects by key in JDO using getObjectsById

On Google Appengine I needed to fetch multiple objects, the key to which is present with me. I tried using PersistenceManager#getObjectsById(Collection) method and passed a list of keys to it. But that threw an exception. On further probing I realized this is not how #getObjectsById works.

There might be other ways of doing it but this is how I’ve done it :

List list = new ArrayList();

for(Key key : <iterate-over-list-of-keys>){

list.add(persistenceManager.newObjectIdInstance(<class-name-here>, key));


Collection objects = persistenceManager.getObjectsById(list);

Hopefully this helps you use the getObjectsById method in JDO on google appengine.

Jun 11

Change Google Chrome Google Search Country

I recently moved to Chile to work on our new startup buffr.com which is an easy way to manage multiple social networks. We call it the social media dashboard.

The first time I used the internet on my laptop in Chile, Google Chrome prompted me if I had changed to a different location. Unaware that clicking yes would make the default search bar use Google Chile, I clicked yes!

After a few searches I realized it was easy changing the chrome google search country back to my own country.

Here’s how you change the country specific google search to the one you want :

1. Close Google Chrome
2. Navigate to \Users\\AppData\Local\Google\Chrome\User Data
3. There will be a file named “Local State”
4. Search for “last_known_google_url” and/or “last_prompted_google_url” and change the extension of the value here to the one you want.
5. Start Google Chrome

You should now have the Google search engine in Chrome belonging to the country that you want. Chrome will prompt you again to use Google specific to your location, just select No!