我有一个List<Person>.我需要List从一个属性获得Person.
例如,我有一个Person班级:
class Person
{
private String name;
private String birthDate;
public String getName() {
return name;
}
public String getBirthDate() {
return birthDate;
}
Person(String name) {
this.name = name;
}
}
List<Person> personList = new ArrayList<>();
personList.add(new Person("David"));
personList.add(new Person("Joe"));
personList.add(new Person("Michel"));
personList.add(new Person("Barak"));
Run Code Online (Sandbox Code Playgroud)
我想获得StreamAPI 的名称列表,如下所示:
List<String> names = personList.stream().somecode().collect(Collectors.toList());
names.stream().forEach(System.out::println);
#David
#Joe
#Michel
#Barak
Run Code Online (Sandbox Code Playgroud)
此代码不起作用:
public class Main
{
public static void main(String[] args)
{
List<Person> personList …Run Code Online (Sandbox Code Playgroud) 我如何使用JavaFx为我的应用程序制作自定义ListView.我需要每个行listView的HBox图像和2个标签.
我有一些代码:
directoryChooser.title = "Select the directory"
val file = directoryChooser.showDialog(null)
if (file != null) {
var files = Files.list(file.toPath())
.filter { f ->
f.fileName.endsWith("zip") && f.fileName.endsWith("ZIP")
&& (f.fileName.startsWith("1207") || f.fileName.startsWith("4407") || f.fileName.startsWith("1507") || f.fileName.startsWith("9007") || f.fileName.startsWith("1807"))
}
for (f in files) {
textArea.appendText(f.toString() + "\n")
}
}
Run Code Online (Sandbox Code Playgroud)
如果我collect(Collectors.toList())在过滤器结束时调用,我得到:
Error:(22, 13) Kotlin: [Internal Error] org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: no descriptor for type constructor of ('Captured(in ('Path'..'Path?'))'..'CapturedTypeConstructor(in ('Path'..'Path?'))?')
Cause: no descriptor for type constructor of ('Captured(in ('Path'..'Path?'))'..'CapturedTypeConstructor(in ('Path'..'Path?'))?')
File …Run Code Online (Sandbox Code Playgroud) 我有一个包含列表和按钮的面板.列表设置MouseAdapter为mouseClick().我添加到面板MouseAdapter与mousePressed()和mouseReleased()和MouseMotionAdapter带mouseDragged.
拖放仅在单击面板时有效.
即使我点击列表,如何使拖动工作?
简单的考试:
public class DragTest extends JFrame{
private boolean drag;
private Point btnCoord;
private Point startPoint;
public DragTest(){
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setSize(500,500);
setLayout(null);
final JPanel panel = new JPanel();
final JButton button = new JButton();
button.setText("Button");
button.setSize(30,60);
button.setLocation(50, 50);
panel.setLayout(null);
setContentPane(panel);
panel.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
if (drag){
panel.setLocation(btnCoord.x-(startPoint.x-e.getX()),btnCoord.y-(startPoint.y-e.getY()));
}
}
});
panel.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
drag …Run Code Online (Sandbox Code Playgroud) java ×4
java-8 ×2
java-stream ×2
collections ×1
javafx ×1
javafx-8 ×1
jlist ×1
kotlin ×1
mouseevent ×1
swing ×1