//Atomic swap between a Hedera Token Service token and hbar
TransferTransaction atomicSwap = new TransferTransaction()
.addHbarTransfer(accountId1, new Hbar(-1))
.addHbarTransfer(accountId2, new Hbar(1))
.addTokenTransfer(tokenId, accountId2, -1)
.addTokenTransfer(tokenId, accountId1, 1)
.freezeWith(client);
//Sign the transaction with accountId1 and accountId2 private keys, submit the transaction to a Hedera network
TransactionResponse txResponse = atomicSwap.sign(accountKey1).sign(accountKey2).execute(client);
//------------------------------------OR---------------------------------------
//Atomic swap between two hedera Token Service created tokens
TransferTransaction atomicSwap = new TransferTransaction()
.addTokenTransfer(tokenId1, accountId1, -1)
.addTokenTransfer(tokenId1, accountId2, 1)
.addTokenTransfer(tokenId2, accountId2, -1)
.addTokenTransfer(tokenId2, accountId1, 1)
.freezeWith(client);
//Sign the transaction with accountId1 and accountId2 private keys, submit the transaction to a Hedera network
TransactionResponse txResponse = atomicSwap.sign(accountKey1).sign(accountKey2).execute(client);