小编joe*_*joe的帖子

打印出数组列表中的所有对象

可能重复:
如何以正确的方式打印对象内容?

我需要能够在我的数组列表中打印出Student对象(所有变量).这可能吗?当我尝试打印时输出这种东西,例如student.Student@82701e.我认为这是hexadecimal什么的

这是我的代码:

package student;

public class Student {

    private String studentName;
    private String studentNo;
    private String email;
    private int year;


    public Student() {
        this.studentName = null;
        this.studentNo = null;
        this.email = null;
        this.year = -1;
    }

    public Student(String nName, String nNum, String nEmail, int nYr) {
        this.studentName = nName;
        this.studentNo = nNum;
        this.email = nEmail;
        this.year = nYr;
    }

    public void setStudentName(String newStudentName) {
        this.studentName = newStudentName;
    }

    public void setStudentNo(String newStudentNo) {
        this.studentNo …
Run Code Online (Sandbox Code Playgroud)

java printing arrays arraylist

9
推荐指数
2
解决办法
14万
查看次数

如何将对象添加到链接列表中?

我一直在从事一个项目,我必须实现一个java类来实现双向链表的使用。我已经完成了 LinkedList 类的所有方法。我只是不确定如何实际将节点对象添加到列表中。这是到目前为止我的代码,测试在底部。任何帮助,将不胜感激。谢谢

public class LinkedList {

    private Node first;
    private Node current;
    private Node last;
    private int currentIndex;
    private int numElements;

    public LinkedList() {
        this.first = null;
        this.last = null;
        this.numElements = 0;
        this.current = null;
        this.currentIndex = -1;
    }

    private class Node {

        Node next;
        Node previous;
        Object data;
    }

    public boolean hasNext() {
        return (current != null && current.next != null);
    }

    public Object next() {
        if (!this.hasNext()) {
            throw new IllegalStateException("No next");
        }

        current = current.next; …
Run Code Online (Sandbox Code Playgroud)

java linked-list doubly-linked-list

5
推荐指数
1
解决办法
8万
查看次数

打印出链接列表

当我尝试打印出我的链接对象列表时,它给了我:

linkedlist.MyLinkedList@329f3d

有没有办法简单地将其作为字符串打印?

package linkedlist;

import java.util.Scanner;

public class LinkedListTest {

    public static void main(String[] args) {
        Scanner keyboard = new Scanner(System.in);
        String item;

        MyLinkedList list = new MyLinkedList();
        System.out.println("Number of items in the list: " + list.size());

        Object item1 = "one";
        Object item2 = "two";
        Object item3 = "Three";

        list.add(item1);
        list.add(item2);
        list.add(item3);

        System.out.println("Number of items in the list: " + list.size());

        System.out.println(list);
}
Run Code Online (Sandbox Code Playgroud)

java printing string linked-list

5
推荐指数
3
解决办法
4万
查看次数

来自ps的列的含义

在Linux bash中,这四列是什么意思ps

例如

PID   TTY         TIME CMD
15286 pts/498 00:00:00 bash
30887 pts/498 00:00:00 ps
Run Code Online (Sandbox Code Playgroud)

linux bash ps

3
推荐指数
1
解决办法
1万
查看次数