I would like to write a linked list like this:
"a" -> "b" -> "c" -> "d"
This is what I've tried so far but it's obviously wrong. I was wondering how to express this correctly in java?
LinkedList<String> s = new LinkedList<>();
s = {"a"->"b"->"c"->"d"};
Thanks!
That's how the pointers in the list look internally, to actually add it to the list you need to do this:
List<String> s = new LinkedList<>();
s.add("a");
s.add("b");
s.add("c");
s.add("d");
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