这是MYLIST:列表中每个节点的字符数? (在链表节点的大小)
[675463645876543456746347543, 985769854789, 3456435]
我需要有类似下面:
System.out.print(mylist.get(1)); ---> 675463645876543456746347543 and it is 27 digits
我如何可以显示每个节点的大小?
这是MYLIST:列表中每个节点的字符数? (在链表节点的大小)
[675463645876543456746347543, 985769854789, 3456435]
我需要有类似下面:
System.out.print(mylist.get(1)); ---> 675463645876543456746347543 and it is 27 digits
我如何可以显示每个节点的大小?
此外,您可以将每个值作为字符串获取到列表中,并获取字符串的长度。
调用每个项目的toString方法并检查String的长度。
System.out.print(mylist.get(1).toString().length());
如果您的列表有一个字符串,你可以使用长度或者你可以转换为int到字符串,使用长度,但如果你有一个整数,你不想要转换阅读:How can I count the digits in an integer without a string cast?。如果你有整数,我建议你采用第二种方法。
列表中的对象的类型是什么? – 2011-12-31 10:15:26
问题如何迭代列表或如何计算每个节点的大小? – 2011-12-31 10:20:24