我有一个递归方法,可以在命令行中打印出值。我需要创建一个带有结果的临时数组,并使用 Swing 显示它。每次循环时如何创建数组并存储值?
static void listSnapshots(VirtualMachine vm)
    {
        if(vm == null)
     {
        JOptionPane.showMessageDialog(null, "Please make sure you selected existing vm");
        return;
     }
    VirtualMachineSnapshotInfo snapInfo = vm.getSnapshot();
    VirtualMachineSnapshotTree[] snapTree = snapInfo.getRootSnapshotList();
    printSnapshots(snapTree);
}
static void printSnapshots(VirtualMachineSnapshotTree[] snapTree)
{
    VirtualMachineSnapshotTree node;
    VirtualMachineSnapshotTree[] childTree;
    for(int i=0; snapTree!=null && i < snapTree.length; i++)
    {
        node = snapTree[i];
        System.out.println("Snapshot name: " + node.getName());
        JOptionPane.showMessageDialog(null, "Snapshot name: " + node.getName());
        childTree = node.getChildSnapshotList();
        if(childTree != null)
        {
            printSnapshots(childTree);
        }
    }//end of for
所以我只有一个带有名称列表的窗口,而不是 JOptionPane,以后可以重用。