I have an array in a line of $a=@(1,2,3,4,56)
. When I do Write-Debug $a
I get an exception in a line of "Array is not a String". If I do $a | out-string | write-debug
I get a list of values in a column. I can write a function that'll write an array in a row (or a string without newlines), but I'd like to know if I'm inventing a bicycle that exists in Powershell, so I can use an existing solution.
Is there a built in function or a not too fancy one-liner to display an array in a format similar to (1,2,3,4,56)
?
Without using loops: * symbol is use to print the list elements in a single line with space. To print all elements in new lines or separated by comma use sep=”\n” or sep=”, ” respectively.
We cannot print array elements directly in Java, you need to use Arrays. toString() or Arrays. deepToString() to print array elements. Use toString() method if you want to print a one-dimensional array and use deepToString() method if you want to print a two-dimensional or 3-dimensional array etc.
Set an array. int[] array = new int[] { 50, 100, 150, 200, 250, 300, 350, 400 }; Now, if you will print this array using a loop and new line, then the arrays will be visible vertically. To work it horizontally, use the Join() method and set spaces to separate array elements.
We declare an array in Java as we do other variables, by providing a type and name: int[] myArray; To initialize or instantiate an array as we declare it, meaning we assign values as when we create the array, we can use the following shorthand syntax: int[] myArray = {13, 14, 15};
Yes, using -join
:
$a -join ','
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With