Java API substring matching