在StringBuffer中附加或+运算符?(append or + operator in StringBuffer?)
在我的项目中有一些使用StringBuffer对象的代码片段,其中的一小部分如下
StringBuffer str = new StringBuffer(); str.append("new " + "String()");
所以我对使用append方法和+运算符感到困惑。
即下面的代码可以写成
str.append("new ").append("String()");
那么上面的两条线是一样的吗?(功能上是的但是)或者它们有什么特别的用法? 即性能或可读性或???
谢谢。
In my project there are some code snippets which uses StringBuffer objects, and the small part of it is as follows
StringBuffer str = new StringBuffer(); str.append("new " + "String()");
so i was confused with the use of append method and the + operator.
ie the following code could be written as
str.append("new ").append("String()");
So are the two lines above same?(functionally yes but) Or is there any particular usage of them? ie performance or readability or ???
thanks.
原文:https://stackoverflow.com/questions/3421720
最满意答案
$DOCKER_HOST
用于告诉$DOCKER_HOST
CLI连接所有命令的位置。 看起来你已经配置了你的,可能是从docker-machine设置到你不再使用的主机。 您可以unset $DOCKER_HOST
以将所有请求发送到本地/var/run/docker.sock
套接字。 或者,您可以将其配置为与root用户的值相匹配。可以将Docker配置为侦听2375(未加密)或2376(需要tls证书设置)以及守护程序的其他标志,但如果您尚未配置这些,则取消设置变量很可能是您的解决方案。 如果您使用的是docker-machine,那么
eval $(docker-machine env -u)
可能就是您想要运行的。The
$DOCKER_HOST
is used to tell the docker CLI where to connect for all commands. It looks like you've configured yours, possibly from a docker-machine setting, to a host you're no longer using. You canunset $DOCKER_HOST
to send all requests to the local/var/run/docker.sock
socket. Or you can configure it to match the value of your root user.Docker can be configured to listen to 2375 (unencrypted) or 2376 (tls certificate setup required) with additional flags to the daemon, but if you have not configured these, unsetting the variable is most likely your solution. If you were using docker-machine, then
eval $(docker-machine env -u)
is likely what you want to run.
相关问答
更多-
刚刚得到它 正如Regan指出的那样,我不得不将用户添加到sudoers组。 但主要原因是我忘记更新存储库缓存,所以apt-get找不到sudo包。 它现在正在工作 以下是完成的代码: FROM ubuntu:12.04 RUN apt-get update && \ apt-get -y install sudo RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo USER doc ...
-
你必须在gitbash中初始化shell,使用: $ $(boot2docker shellinit) 在终端。 以下是mac的文档: https : //docs.docker.com/installation/mac/ 。 You have to init shell inside gitbash, use: $ $(boot2docker shellinit) in terminal. Here is documentation for mac: https://docs.docker.com ...
-
由于tcp超时,docker无法连接到boot2docker(docker can't connect to boot2docker because of tcp timeout)[2023-08-19]
我也有这个问题,这里是临时解决方案。 首先,打开virtualbox并检查boot2docker vm上的网络设置,以查看host only于host only适配器。 在我的情况下,它是vboxnet1; 对你来说,它可能是vboxnet0。 然后,应用此命令: sudo route -nv add -net 192.168.59 -interface vboxnet1 现在你应该可以运行docker命令了。 有关详细信息,请参阅此问题 编辑 :我注意到随着时间的推移,这个问题的共同点是cisco an ... -
以下命令导出后续docker命令使用的几个环境变量: eval "$(docker-machine env default)" 但是,如果使用sudo启动docker,docker可执行文件将无法访问导出的环境变量。 您可以通过将-E标志传递给sudo来使其工作,例如: sudo -E docker pull fluxcapacitor/pipeline 但更容易的选择是使用没有root的docker,比如: docker pull fluxcapacitor/pipeline The followi ...
-
尝试连接时发生错误 - 不使用sudo时的docker(An error occurred trying to connect - docker when not using sudo)[2023-05-29]
$DOCKER_HOST用于告诉$DOCKER_HOST CLI连接所有命令的位置。 看起来你已经配置了你的,可能是从docker-machine设置到你不再使用的主机。 您可以unset $DOCKER_HOST以将所有请求发送到本地/var/run/docker.sock套接字。 或者,您可以将其配置为与root用户的值相匹配。 可以将Docker配置为侦听2375(未加密)或2376(需要tls证书设置)以及守护程序的其他标志,但如果您尚未配置这些,则取消设置变量很可能是您的解决方案。 如果您使用的是 ... -
从Docker snap软件包中``sudo docker build .`失败(`sudo docker build .` fails from Docker snap package)[2021-12-29]
由于不断变化的快速模型中的限制问题,默认情况下,Docker并不是完整的版本( 请参阅Snapcraft论坛上的讨论 )。 要获得一些有用的指导说明如何解决(即打破)限制模型,直到适当的修复到位。 您可以简单地检查在快照中打包的Docker帮助应用程序。 $ docker.help Docker snap: Docker Linux container runtime. Due to the confinement issues on snappy, it requires some manual set ... -
自从其内核包版本3.18以来,Ubuntu放弃了对AUFS的支持,因为从该版本开始,OverlayFS是Linux内核的一部分。 我认为您的docker守护程序正在尝试使用AUFS驱动程序,因为您有一个/var/lib/docker/aufs文件夹。 无论如何,在运行--storage-driver=守护程序时,您可以使用-s或--storage-driver=选项强制使用正确的存储驱动程序。 首先,要测试守护程序是否与OverlayFS存储驱动程序一起使用,请在终端中运行守护程序: sudo docker ...
-
有一些选项,最好的方法是在没有root的情况下使docker可用: https : //docs.docker.com/engine/installation/linux/linux-postinstall/ 选项1:使用gcloud时指定完整路径。 sudo $(which gcloud) 选项2:以root身份安装glcoud sudo su #install gcloud gcloud version 但是,最好的办法是使用docker作为非root :) There are a few opt ...
-
尝试运行此命令docker build -t tutorial . 没有sudo或运行eval "$(docker-machine env default)"和sudo Try run this command docker build -t tutorial . without sudo or run eval "$(docker-machine env default)" with sudo
-
目标应如下所示: kill: for c in $$(sudo docker ps -q); do sudo docker kill $$c; done 更新:事实证明docker kill使用多个容器作为参数,所以只需转义美元就足以杀死所有容器 kill: sudo docker kill $$(sudo docker ps -q) The target should look like this: kill: for c in $$(sudo docker ps -q); d ...