如何修复不兼容的类型错误

时间:2022-02-28 08:47:16

I have two printf they are separate because one is doing a loop I am having trouble aligning one of the printf. I want it tho line up under friends.

我有两个printf它们是分开的,因为一个正在循环我无法对齐其中一个printf。我希望它在朋友面前排队。

What is printing

什么是印刷品

Member                     Friends             
Chi Cho                 Joe Blow
                 Jimmy Brown
Status: 

Joe Blow                 John Ko
Status: Coding like a friend

Tammy Joe                 Joe Johnson
Status: this is great

Bing Smith                 John Brown
Status: This sucks

what I am trying to get

我想要得到什么

Member                     Friends             
Chi Cho                    Joe Blow
                           Jimmy Brown
Status: 

Joe Blow                   John Ko
Status: Coding like a friend

Tammy Joe                  Joe Johnson
Status: this is great

Bing Smith                 John Brown
Status: This sucks

    for (int i = 0 ; i< profiles; i++)
    {
    String arrayName = face.get(i).getName();       
    String statusName = face.get(i).getStatus();

    LinkedList<String> linkName = face.get(i).getFriend();
    String realname ="";
   System.out.printf("%-20s", arrayName);

   for (String toname : linkName) {
        System.out.printf("%-20s", toname);
        System.out.println();

Where the error is

错误在哪里


if (toname != linkName.size() - 1) {
            System.out.printf("%-20s", "");
            }
    }

    System.out.println("Status: " + statusName);
    System.out.println();
    }
}

2 个解决方案

#1


6  

Its called size() in Lists :) check here

它在列表中称为size():)在这里查看

#2


2  

The above snippet would become this if you are using a list:

如果您使用列表,上面的代码段将成为这个:

if (toname != arraylistName.get(arraylistName.size() - 1)) {
    System.out.printf("%-20s", "");
}

#1


6  

Its called size() in Lists :) check here

它在列表中称为size():)在这里查看

#2


2  

The above snippet would become this if you are using a list:

如果您使用列表,上面的代码段将成为这个:

if (toname != arraylistName.get(arraylistName.size() - 1)) {
    System.out.printf("%-20s", "");
}