我试图删除一些元素ArrayList迭代它像这样:
for (String str : myArrayList) {
if (someCondition) {
myArrayList.remove(str);
}
}
Run Code Online (Sandbox Code Playgroud)
当然,我ConcurrentModificationException试图在迭代时同时从列表中删除项目时得到一个myArrayList.有没有一些简单的解决方案来解决这个问题?
我正在练习使用多个文件和头文件等.所以我有这个项目需要两个数字,然后添加它们.很简单.
这是我的文件:
main.cpp中
#include <iostream>
#include "add.h"
int main()
{
int x = readNumber();
int y = readNumber();
writeAnswer(x + y);
return(0);
}
Run Code Online (Sandbox Code Playgroud)
io.cpp
int readNumber()
{
int x;
std::cout << "Number: ";
std::cin >> x;
return x;
}
void writeAnswer(int x)
{
std::cout << "Answer: ";
std::cout << x;
}
Run Code Online (Sandbox Code Playgroud)
add.h
#ifndef ADD_H_INCLUDED
#define ADD_H_INCLUDED
int readNumber();
void writeAnswer(int x);
#endif // #ifndef ADD_H_INCLUDED
Run Code Online (Sandbox Code Playgroud)
错误显示在io.cpp中.确切的错误是:
有谁知道为什么会这样?谢谢.
编辑:我昨天用相同数量的文件(2 .cpp和1.h)做了一个小项目,我没有在另一个.cpp中包含iostream标题,它仍然编译并运行正常.
是否有可能Enter在java中输入JTextField 时检测到有人按下了什么?无需创建按钮并将其设置为默认值.
我有wstring格式的Windows注册表键值.现在我想将它传递给这个代码(第一个参数 - javaw.exe的路径):
std::wstring somePath(L"....\\bin\\javaw.exe");
if (!CreateProcess("C:\\Program Files\\Java\\jre7\\bin\\javaw.exe", <--- here should be LPCTSTR, but I have a somePath in wstring format..
cmdline, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
0, // Set handle inheritance to FALSE.
CREATE_NO_WINDOW, // ON VISTA/WIN7, THIS CREATES NO WINDOW
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi)) // Pointer to PROCESS_INFORMATION structure.
{
printf("CreateProcess …Run Code Online (Sandbox Code Playgroud) 当两个线程同时调用相同的静态方法时会发生什么?例如:
public static String someMethod(){
//some logic, can take about 1 second to process
return new String(result);
}
Run Code Online (Sandbox Code Playgroud)
第一个线程现在调用someMethod().第二个线程从现在起0.5秒后调用someMethod()(第一个线程仍在处理数据).
我知道someMethod()可以同步.但如果不同步会发生什么?
我注意到Glassfish-5 Web服务器仅使用一个Set-Cookie标头发送响应,其中包含多个cookie.当我用萤火虫看时,我可以看到它们被未知的角色分开.无论如何 - Firefox只读取第一个cookie.如何配置Glassfish5发送多个Set-Cookie标头 - 每个cookie一个?rfc6265指出:
- 概述
...
源服务器不应该将多个Set-Cookie头字段折叠到单个头字段中.折叠HTTP头字段的常用机制(即,如[RFC2616]中所定义)可能会更改Set-Cookie头字段的语义,因为Set-Cookie以一种冲突的方式使用%x2C(",")字符有这样的折叠.
...
此外在这里它指出:
当发送带有多个cookie的HTTP响应时,CFHTTPMessage将cookie组合到单个"Set-Cookie"HTTP头下的逗号分隔列表中.(这被称为"set-cookie-folding".)
Google Chrome,Firefox和Internet Explorer不支持设置Cookie折叠.这些浏览器中的每一个都会在第一个逗号后完全忽略每个cookie,使得CFHTTPMessage完全无用于在除Safari之外的任何浏览器中处理具有多个cookie的HTTP响应(支持cookie折叠).
这就是响应在firebug上看起来的样子:
两个饼干由未知字符联合.正如我所注意到的那样 - 像Apache这样的其他服务器Set-Cookie通过新行字符在一个标题中分割多个cookie .
我注意到这只发生在HTTPS连接上.
另外,我在Github上开设了一个问题在这里.
尝试在Tomcat 9 Web服务器上运行相同的Web应用程序 - Set-Cookie标题cookie由新行字符分隔,它的工作方式与预期相符...

相同的响应,但在Glassfish5上,再次 - cookie由未知字符加入,并且不被Firefox接受(只是第一个):

在NetBeans IDE 8.2 HTTP Server Monitor中我可以看到,发送了2个cookie - 看起来没问题:

再次使用FireFox - 一个Set-Cookie标头中的2个Cookie:

Firefox Developer Edition上也是如此:

完全糊涂..
Glassfish 5使用Grizzly Framework 2.4.0 - 我认为可以在grizzly-http-servlet-2.4.0-sources.jar中找到源代码 - 但找不到将cookie连接在一起的代码段.
我现在可以确认它只与HTTP/2.0协议有关,通过启用/禁用network.http.spdy.enabled.http2在Firefox上测试about:config.在HTTP/1.1上通过HTTPS cookie按预期设置.
我已经实现了SSLServerSocket,当我启动.jar文件时可以选择-Djavax.net.debug=ssl:handshake调试安全握手,我也得到这些消息(在建立一些安全连接之前):
...
Ignoring unavailable cipher suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
Ignoring unavailable cipher suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA
Ignoring unavailable cipher suite: TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_128_CBC_SHA256
Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_256_CBC_SHA256
Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_256_CBC_SHA256
Ignoring unavailable cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
Ignoring unavailable …Run Code Online (Sandbox Code Playgroud) 在我的游戏中,我希望能够使用右移和左移键来实现不同的功能.在Java(或其他语言)中,有没有办法区分这两者?
KeyEvent类只有VK_SHIFT,它对应左右Shift键.同样的,Control,Alt,Enter,等.
我主要担心的是有人可能会用两根手指同时快速按下两个按键,从而获得不公平的优势.我应该关注这件事吗?
我的目标是简化这段代码(一切正常):
package test;
import java.awt.Window;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.JWindow;
public class A extends JWindow implements MouseListener, MouseMotionListener {
public A() {
addMouseListener(A.this);
addMouseMotionListener(A.this);
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
//This method is being used, working fine
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseDragged(MouseEvent e) {
//This method is being …Run Code Online (Sandbox Code Playgroud) 电子邮件地址本地部分允许注释 - 例如cat(veryangry)lives@inmyhouse.com,是否可以在电子邮件域部分添加注释,如 - catlives@(veryangry)inmyhouse.com?SMTP服务器会接受吗?
刚试过POSTFIX - 即使在电子邮件本地部分也拒绝了电子邮件评论...在域部分接受,但我认为这些评论无法识别(或POSTFIX电子邮件过滤器不是那么严格).
修改我的SMTP服务器电子邮件过滤器..现在删除了所有电子邮件注释,但如果邮件被中继 - 不清楚是否也应该发送邮件.可能是许多SMTP服务器不接受这样的电子邮件..试图在RFC中找到一些信息..