简体   繁体   English

打印没有括号的对象数组

[英]print array of objects without brackets

How can i print an array from a 2d without brackets. 如何从没有括号的2d打印数组。 Basically am adding first the array with the new values to a 2d with : 基本上我首先使用新值将数组添加到2d:

books=(Object[][]) Arrays.copyOf(row,2);

whereas books is already initialized as 2d array with : 而书籍已经初始化为2d数组,其中:

    static Object[][] books=new Object[1][1];

BUT when I try to print the first row from books with : 但是当我尝试从书中打印第一行时:

System.out.println(Arrays.deepToString(books[0])+" ");

it prints me brackets and commas 它打印括号和逗号

[asds,asdas,223]

like is suppose to do. 喜欢这样做。

How can i remove those? 我怎么能删除那些?

Thank you ! 谢谢 !

您可以使用replaceAll并简单地:

myStr = myStr.replaceAll("\\[|\\]", "");

Try this 尝试这个

    StringBuilder builder = new StringBuilder();

    for (String value : publicArray) {

       builder.append(value +",");

       // or builder.append(value).append(",");
    }

    String text = builder.toString();
    System.out.print(text);

You can try this 你可以试试这个

String output ;
    for(String s: books[0]){
      output = output +s+ ",";
    }
output = output.substring(0, output.length()-1);
System.out.print(output);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM