It depends on the 401(k) plan, but in general the answer would be “yes,” if you’re willing to pay the penalty.
It is generally a pretty bad idea to withdraw 401(k) money early.
If you withdraw the money before age 59½, the money will be subject to a 10% penalty in addition to regular income taxes. There are exemptions from the penalty, but there fewer exemptions in a 401(k) than an IRA.
In an IRA the penalty can be waived for first-time homebuyer’s expenses up to $10,000, or even for educational expenses, but in a 401(k) the 10% penalty will still be levied if withdrawals are made for these reasons — and a plan may not even permit such withdrawals.
If a plan does permit hardship withdrawals, for immediate financial needs, the employee can take the money out, but will still incur the IRS penalty. Plans may allow various other types of in-service withdrawals, which employees can potentially use to roll assets over into a personal IRA while they still work at a company, but you should find out what is permitted in your plan.
The plan may also permit loans, which are not taxable if they are repaid on time, which is usually within about 2 years.