------
## 最终结论
```python
def threeSumClosest(nums, target):
    nums.sort()  # 首先对数组进行排序
    closest_sum = sum(nums[:3])  # 初始化最接近的和为前三个数的和
    n = len(nums)
    
    for i in range(n - 2):  # 遍历数组中的每一个元素
        left, right = i + 1, n - 1  # 双指针查找另外两个数
        
        while left < right:
            current_sum = nums[i] + nums[left] + nums[right]
            
            if abs(current_sum - target) < abs(closest_sum - target):
                closest_sum = current_sum  # 更新最接近的和
            
            if current_sum < target:
                left += 1
            elif current_sum > target:
                right -= 1
            else:
                return current_sum  # 如果正好等于目标值，直接返回
    
    return closest_sum  # 返回最接近的和

# Example usage:
nums = [-1, 2, 1, -4]
target = 1
print(threeSumClosest(nums, target))  # Output: 2
```