如何打印数组?

发布于 2025-02-11 01:16:48 字数 1167 浏览 1 评论 0原文

我正在尝试使用Eclipse中的JSWING和JAVA-WS创建一个库存系统,并且我坚持尝试将哈希变成阵列。我绝不是Java的专家,所以我来这里寻求帮助。

这是代码:

@Override
public InventoryItem [] getAllInventoryItem() {
    ArrayList<InventoryItem> items = new  ArrayList<InventoryItem>();
    InventoryItem item=null;
    
    for(Map.Entry<String, InventoryItem> e : inventories.entrySet())
    {
        item=new InventoryItem();
        item.setBrand(e.getValue().getBrand());
        item.setCode(e.getKey());
        item.setName(e.getValue().getName());
        items.setPrice(e.getValue().getPrice());
        
        items.add(item);
    }
    return (InventoryItem []) items.toArray(new InventoryItem[items.size()]);
}

但是当我调用方法时:

System.out.println((inventory.getAllInventoryItem()));

这就是出来的:

[Lcom.lansang.inventory.fx.InventoryItem;@123772c4

我也尝试了:

System.out.println((Arrays.toString(inventory.getAllInventoryItem())));

但是,我仍然没有在数组中得到元素。它只会返回以下内容:

[com.lansang.inventory.fx.InventoryItem@123772c4, com.lansang.inventory.fx.InventoryItem@2d363fb3]

I'm trying to create an Inventory System with a GUI using JSwing and JAVA-WS in Eclipse and I am stuck on trying to turn the Hash into an array. I am in no way an expert in Java, so I came here to ask for help.

Here's the code:

@Override
public InventoryItem [] getAllInventoryItem() {
    ArrayList<InventoryItem> items = new  ArrayList<InventoryItem>();
    InventoryItem item=null;
    
    for(Map.Entry<String, InventoryItem> e : inventories.entrySet())
    {
        item=new InventoryItem();
        item.setBrand(e.getValue().getBrand());
        item.setCode(e.getKey());
        item.setName(e.getValue().getName());
        items.setPrice(e.getValue().getPrice());
        
        items.add(item);
    }
    return (InventoryItem []) items.toArray(new InventoryItem[items.size()]);
}

But when I call the method:

System.out.println((inventory.getAllInventoryItem()));

This is what comes out:

[Lcom.lansang.inventory.fx.InventoryItem;@123772c4

I also tried:

System.out.println((Arrays.toString(inventory.getAllInventoryItem())));

But still, I dont get the elements inside the array. It only returns this:

[com.lansang.inventory.fx.InventoryItem@123772c4, com.lansang.inventory.fx.InventoryItem@2d363fb3]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抱着落日 2025-02-18 01:16:48

也许是:

(inventory.getAllInventoryItem()).stream()
 .forEach(System.out::println);

Maybe this:

(inventory.getAllInventoryItem()).stream()
 .forEach(System.out::println);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文