0

Question2:

I'm confused on ArrayList<Object>, please explain to me the following:

I have a class Node which has two fields: data1 and data2

public class Node {
    private static int data1;
    private static int data2;
 
    public Node(){...}
    public static void setData1(int data);
    public static void getData1();
    public static void setData2(int data);
    public static void getData2();
} // end of class Node

And then I have another class called Link.

public class Link {
    private ArrayList<Node> linkList = new ArrayList<Node>();
    private Node node = new Node();
    ...
    linkList.add(node)
    linkList.get(how to do it here)
} // end of class Link

I want to output the Node data inside linkList.

linkList.get(how to do it here)

How would I do that?


Vertically centering a
    menu on a HTML page

I have very little CSS experience, so this is probably a very elementary question. I am having problems vertically centering a <ul> menu in the middle of the page. I've tried the following:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <style type="text/css">
            body, html {
                height: 100%;
                margin: 0;
                padding: 0;
            }
            div {
                width: 100%;
                height: 100%;
                position: absolute;
                display: table;
                text-align: center;
                vertical-align: middle;
                border: 10pt solid black;
            }
            ul {
                display: block;
            }
            ul li {
                display: inline-block;
                background-color: yellow;
                border: 1pt solid black;
            }
        </style>
    </head>
    <body>
        <div>
            <ul>
                <li>item 1</li>
                <li>item 2</li>
                <li>item 3</li>
            </ul>
        </div>
    </body>
</html>

What am I doing wrong?

4

2 に答える 2

1

OPは次を使用して解決しました:

linkList.get(0).getData();
于 2015-05-21T14:16:14.070 に答える
1

あなたは単に次のようなことをするのを忘れていたと思います

private ArrayList<node> linkList = new ArrayList<node>();

試す:

public class Link {
    private ArrayList<node> linkList = new ArrayList<node>();
    private node nodelist = new node();
    ...
    linkList.add(nodelist)
} // end of class link

編集

ここから取得した次のサンプル コードを見て、操作方法を理解してください。ArrayList<...>

java.util.ArrayList<String>  v = new java.util.ArrayList<String>();
    v.add( "able" );
    v.add( "baker" );
    v.add( "charlie" );
    v.add( "delta" );

int n = v.size();
for(int i = 0; i < n ; i++)
    System.out.println( v.get( i ) );
于 2012-11-13T06:12:37.817 に答える