我的 .txt 文件中有以下示例数据
111, Sybil, 21
112, Edith, 22
113, Mathew, 30
114, Mary, 25
Run Code Online (Sandbox Code Playgroud)
所需的输出是
[{"number":"111","name":"Sybil","age":"21" },
{"number":"112","name":"Edith","age":"22"},
{"number":"113","name":"Mathew","age":"30"},
"number":"114","name":"Mary","age":"25"]
Run Code Online (Sandbox Code Playgroud)
可悲的是,我并没有走得太远,因为我似乎无法从每一行中获取值。相反,这就是显示的内容
[一二三]
private void loadFile() throws FileNotFoundException, IOException {
File txt = new File("Users.txt");
try (Scanner scan = new Scanner(txt)) {
ArrayList data = new ArrayList<>() ;
while (scan.hasNextLine()) {
data.add(scan.nextLine());
System.out.print(scan.nextLine());
}
System.out.print(data);
}
Run Code Online (Sandbox Code Playgroud)
我将不胜感激任何帮助。谢谢
我有一个值列表,最多包含四个元素。我需要循环遍历列表,并且仅在某些情况下才需要抛出异常。需要抛出异常的不同场景如下。
List<String> values = ["test1","test2",null,"test4"];
List<String> values = ["test1",null,"test3","test4"];
List<String> values = ["test1",null,null,"test4"];
Run Code Online (Sandbox Code Playgroud)
List<String> values = [null,"test2","test3","test4"];
List<String> values = [null,null,"test3","test4"];
List<String> values = [null,null,null,"test4"];
Run Code Online (Sandbox Code Playgroud)
所有其他情况都是有效的,不应引发异常。有效案例有:
List<String> values = ["test1","test2","test3","test4"];
List<String> values = ["test1","test2","test3",null];
List<String> values = ["test1","test2",null,null];
List<String> values = ["test1",null,null,null];
List<String> values = [null,null,null,null];
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
我似乎对 IntelliJ 有关于setOnActionlambda 函数的问题。经过大量研究,我找不到我的问题的答案。
我正在学习用 Java(最新的 JDK 8 版本)编程,最近从 NetBeans 转移到 IntelliJ IDE。我编写了一个非常简单的程序,代码在 NetBeans 中完美运行,但是我在使用 IntelliJ 时遇到了问题。
setOnActionIntelliJ 无法识别该函数。我已经配置了 IDE(项目结构/模块/并选择了 8 - Lambda's,类型注释,...)但没有成功。我手动添加:import javafx.event.ActionEvent;
我还配置了(设置/常规/自动导入/动态添加明确的导入)。
该程序包含两个类,一个 Main 类和一个 GUI 类。
主要类:
package fxvb0203;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;
public class fxvb0203 extends Application
{
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage primaryStage)
{
FlowPane root = new FlowPane();
Scene scene = new Scene(root);
new GUI(root);
primaryStage.setTitle("Test");
primaryStage.setScene(scene);
primaryStage.show(); …Run Code Online (Sandbox Code Playgroud) 我想在枚举中使用 lombok,但找不到生成构造函数的注释。我检查了 Lombok 手册,它显示应该有一个名为 @XArgsConstructor 的注释,但我找不到它,有什么建议吗?谢谢。
在此JavaBeans上的Oracle文档中,我们看到:
public class FaceBean {
private int mMouthWidth = 90;
public int getMouthWidth() {
return mMouthWidth;
}
public void setMouthWidth(int mw) {
mMouthWidth = mw;
}
}
Run Code Online (Sandbox Code Playgroud)
不应该是财产mouthWidth吗?
大家都知道,IteratorS按返回ArrayList,HashMap,HashSet等都是快速失败的,但在使用迭代器remove()不会抛出ConcurrentModificationException.怎么样?
ConcurrentModificationException如果在迭代时修改了集合,则抛出fail-fast迭代器.但是从迭代器中删除元素ArrayList或HashSet使用迭代器时remove(),不会抛出任何元素ConcurrentModificationException.请详细解释.
谢谢
ArrayListJava中的最大容量是多少?由于ArrayList在内部使用数组,它的容量将是Integer.MAX_VALUE,对吗?
此代码显示的最大容量ArrayList为Integer.MAX_VALUE:
public class ArrayList<E> extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, java.io.Serializable
{
transient Object[] elementData; // non-private to simplify nested class access
/**
* The size of the ArrayList (the number of elements it contains).
*
* @serial
*/
private int size;
/**
* The maximum size of array to allocate (unless necessary).
* Some VMs reserve some header words in an array.
* Attempts to allocate larger arrays may …Run Code Online (Sandbox Code Playgroud)