How do I make this print the contents of b rather than its memory address?
public class Testing {
public static void main (String [] args){
String a = "A#b#C ";
String[] b = a.split("#");
System.out.println(b);
}
}
You can use Arrays.toString to print the String representation of your array: -
System.out.println(Arrays.toString(b);
This will print your array like this: -
[A, b, C ]
Or, if you want to print each element separately without that square brackets at the ends, you can use enhanced for-loop: -
for(String val: b) {
System.out.print(val + " ");
}
This will print your array like this: -
A b C
If you want each element printed on a separate line, you can do this:
public class Testing {
public static void main (String [] args){
String a = "A#b#C ";
String[] b = a.split("#");
for (String s : b) {
System.out.println(s);
}
}
}
For a result like [A, b, C], use Rohit's answer.
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