我们如何确保列表中的各个字符串不为空/空或遵循特定模式
@NotNull
List<String> emailIds;
Run Code Online (Sandbox Code Playgroud)
我还想添加一个模式
@Pattern("\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b.")
但我可以没有它.但我肯定希望有一个约束,它将检查列表中的任何字符串是否为空或空白.Json架构也将如何
"ids": {
"description": "The ids associated with this.",
"type": "array",
"minItems": 1,
"items": {
"type": "string",
"required" :true }
}
"required" :true does not seem to do the job
Run Code Online (Sandbox Code Playgroud) 我需要找到在另一个操作中显示多个操作的方法,就像 Netbeans 使用Run Main Project图标那样。
您可以看到有一个默认操作Run Main Project,如果单击绿色播放图标旁边的小箭头,您可以选择特定操作,例如Run。
我正在检查代码Netbeans,但找不到在我的应用程序中执行此操作的代码。
我有一个类型的哈希图String,ArrayList<String>.两个不同keys的存储在哈希映射中,其中包含值列表.
现在我必须比较不同键的值并提取公共值.怎么能实现这个功能?
以下是Hashmap我使用的类型:
示例列表:
{Size=[43, 53, 63, 48, 58], Color=[66, 62, 65, 64, 63]}
Run Code Online (Sandbox Code Playgroud)
这是代码......
private HashMap<String, ArrayList<String>> mapMatchvalues = new HashMap<>();
for (Map.Entry<String, ArrayList<String>> map3 : mapMatchvalues.entrySet()) {
List<String> getList1 = new ArrayList<>();
getList1 = map3.getValue();
for (int i = 0; i < getList1.size(); i++) {
if (getList.contains(getList1.get(i))) {
//Print values
} else {
// Print if not matched....
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试Spring-boot使用 Hibernate 和 REST -API 构建 CRUD 应用程序。但是,当我尝试运行该应用程序时,一切正常,但控制台显示以下错误
java.lang.NullPointerException: null
at io.javabrains.EmployerController.getAllEmployers(EmployerController.java:20) ~[classes/:na]
Run Code Online (Sandbox Code Playgroud)
我尝试更改该值,但没有成功
雇主服务.java
package io.javabrains;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Service;
import io.javabrains.Entity.Employer;
@Service
public class EmployerService {
private Repository repository;
public List<Employer>getAllEmployers(){
List<Employer>employers = new ArrayList<>();
repository.findAll()
.forEach(employers::add);
return employers;
}
public void addEmployer(Employer employer) {
repository.save(employer);
}
}
Run Code Online (Sandbox Code Playgroud)
雇主控制器.java
package io.javabrains;
import java.util.List;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import io.javabrains.Entity.Employer;
@RestController
public class EmployerController {
private EmployerService service;
@RequestMapping("/employer") …Run Code Online (Sandbox Code Playgroud) 当我运行测试用例时,Iam低于Exception,这是在我的chrome浏览器更新到62.0版本之后发生的.我已经将Chrome驱动程序更新为2.33版本,即使在更新后面临同样的问题.使用的硒版本是2.52
org.openqa.selenium.WebDriverException: unknown error: cannot get automation extension
from unknown error: page could not be found: chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html
(Session info: chrome=62.0.3202.94)
(Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 10.10 seconds
Build info: version: '2.35.0', revision: '8df0c6bedf70ff9f22c647788f9fe9c8d22210e2', time: '2013-08-17 12:46:41'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_71'
Session ID: 30ad534f9914fe71f672dd12e56a0aea
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=C:\Users\ab83622\AppData\Local\Temp\scoped_dir6624_25177, chromedriverVersion=2.29.461591 (62ebf098771772160f391d75e589dc567915b233)}, networkConnectionEnabled=false, unexpectedAlertBehaviour=, rotatable=false, …Run Code Online (Sandbox Code Playgroud) 我正在尝试进行 oAuth2 DB 身份验证,下面是我使用 tokenUrl 作为的代码片段
http://localhost:8025/oauth2db/oauth/token?grant_type=password&username=nithi5@gmail.com&password=nithi%
HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(tokenUrl);
try {
String auth = authConfiguration.getDatabaseClientId() + ":" + authConfiguration.getDatabaseClientSecret();
byte[] authEncrypted = Base64.encodeBase64(auth.getBytes(Charset.forName("ISO-8859-1")));
httpPost.setHeader("Authorization", "Basic " + new String(authEncrypted));
}
HttpResponse httpResponse = httpClient.execute(httpPost);
Run Code Online (Sandbox Code Playgroud)
在这样做时,我收到错误
"Malformed escape pair at index 103: http://localhost:8025/oauth2db/oauth/token?grant_type=password&username=nithi5@gmail.com&password=nithi%"
Run Code Online (Sandbox Code Playgroud)
下面我附上完整的日志
2018-02-14 11:28:08.991 INFO 18028 --- [nio-8027-exec-1] c.a.s.c.oauth2.OAuth2Controller : *********Login WithDataBase*****************
2018-02-14 11:28:08.991 INFO 18028 --- [nio-8027-exec-1] com.altimetrik.security.util.OAuth2Util : token URLhttp://localhost:8025/oauth2db/oauth/token?grant_type=password&username=nithi5@gmail.com&password=nithi%
2018-02-14 11:28:09.004 ERROR 18028 --- [nio-8027-exec-1] c.a.s.exception.RESTExceptionHandler : Error occured …Run Code Online (Sandbox Code Playgroud) 我使用的是 Windows 10。我已JAVA_HOME为系统和用户定义了 my 和 path 变量:
C:\Program Files\Java\jdk-11.0.2\bin
Run Code Online (Sandbox Code Playgroud)
我使用 IntelliJ 创建了一个 Spring Boot 项目。
当我 git bash 进入项目文件夹并尝试执行时:
./mvnw clean
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
JAVA_HOME未正确定义。我们无法执行C:/Program Files/Java/jdk-11.0.2/bin/bin/java
这些多余的东西到底是/bin从哪里来的呢?
谢谢你的帮助,马克
我对 Java 并不陌生Collections,但我对以下场景感到困惑。
在我的项目中,我实现了这样的代码:
List<String> obj_lStr= new ArrayList<String>();
String[] obj_arrStr = {"someString", "noString", "abcString"};
obj_lStr.addAll(Arrays.asList(obj_arrStr));
Run Code Online (Sandbox Code Playgroud)
但在代码审查期间,我的项目负责人指示我更改此代码并在不使用的情况下实现它String[] obj_arrStr.
然后我将代码更改为:
obj_lStr.addAll(Arrays.asList( { "someString", "noString", "abcString" }));
Run Code Online (Sandbox Code Playgroud)
但我遇到编译错误:
Main.java:13: error: illegal start of expression
x.addAll(Arrays.asList({"someString", "noString", "abcString"}));
^
Main.java:13: error: ')' expected
x.addAll(Arrays.asList({"someString", "noString", "abcString"}));
^
Main.java:13: error: ';' expected
x.addAll(Arrays.asList({"someString", "noString", "abcString"}));
Run Code Online (Sandbox Code Playgroud)
我将代码行更改为:
obj_lStr.addAll(Arrays.asList("someString", "noString", "abcString"));
Run Code Online (Sandbox Code Playgroud)
然后编译错误就消失了。
问:为什么会这样呢?为什么asList()方法会引发编译错误 with {"","",""},而不是 for ("","","")?
我可以输出学生的详细信息,但总是在我这样做时显示
Exception in thread "main" java.lang.NullPointerException
at client.Client.main(Client.java:126)
Run Code Online (Sandbox Code Playgroud)
并且程序崩溃。
数组是null,我不知道为什么,我不知道如何解决这个问题。请帮我理解,问题应该在这里..
if (choice == 3) {
for (int a = 0; a < list.length; a++) { //To Display all current Student Information.
// list[i] = new student();
list[a].DisplayOutput();
}
Run Code Online (Sandbox Code Playgroud)
无论如何,这里是我的代码。
package client;
import java.util.Scanner;
public class Client {
//my infos
public static void AuthorInformation() {
System.out.print("__________________________________________\n"
+ "Student Name: xxxxxx xxxxxx\n"
+ "Student ID-Number: xxxxxx\n"
+ "Tutorial Timing: Wednesday 9:30 - 12:30 \n"
+ "Tutor Name: Mr xxxxxx\n\n"
+ …Run Code Online (Sandbox Code Playgroud) 所以我最近去过面试,并被问到以下问题.(实际上这只是一个测试写作,所以我不能问任何问题)
在main方法的最后,有多少对象可以进行垃圾回收?
public class Main {
public static void main(String[] args) {
Object obj;
for (int i = 0; i < 5; i++) {
obj = new Object();
}
obj = null;
}
}
Run Code Online (Sandbox Code Playgroud)
(A)0
(B)1
(C)5
我知道它是0,因为至少有一个object(obj)将被垃圾收集,但我也知道它obj不是真正的对象,它只是对它的引用.所以我的回答是5.
那是对的吗?如果没有,那么为什么呢?
ArrayList声明从java版本1 修改为另一个ArrayList.修改声明的优点是什么.
例如:这里我提到了各种版本的Java支持的三种声明.我在Eclipse中设置了Java Compilance leve 1.4
ArrayList val=new ArrayList();//Supported at 1.4
ArrayList<String> val=new ArrayList<String>();//Syntax error, parameterized types are only available if source level is 1.5 or greater
ArrayList<String> val=new ArrayList< >();//operator is not allowed for source level below 1.7
Run Code Online (Sandbox Code Playgroud) 我有一个关于解决问题Iphone 6和Iphone 6 Plus.我想了解一下@x2和@x3我真正需要的是肯定的!
如果我有一个全屏UIImageView,显示Iphone 6(667x375 points)包含UIImage 1334x750的大小必须是因为点的大小667(@x2)x375(@x2),对吧?
所以,如果我理解,在UIImageView的Iphone 6Plus全屏的736x414,但分辨率是@x3那么UIImage的UIImageView必须2208x1242,因为点大小736(@x3)x414(@x3),不是吗?
然后在一般情况下,我只需要知道我的UIImageView的大小是多少,如果分辨率是@x2i乘以大小x2,如果分辨率@x3乘以大小x3?
伙计我真的需要确认,如果我错了,请解释我原因!
如果您认为我的问题非常愚蠢,我很抱歉,但我需要了解它的工作原理.
亲切:)