How can we append a given string to the end of a list? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can we append a given string to the end of a list?

15th Nov 2018, 11:18 AM
Sin
14 Answers
+ 2
Sin There isnt difference... A list contains an attribute pointing to first elemtent and any element contain the next one... Then, you have to go to last element (which has next attribute to null) and append to it (eg. Set his next attribute) a new element... This works for any type
15th Nov 2018, 2:12 PM
KrOW
KrOW - avatar
+ 1
Sin Then you have to implement a custom list? Its not clear from description
15th Nov 2018, 1:00 PM
KrOW
KrOW - avatar
+ 1
Sin Start with implements StringElement... You know how list works?
15th Nov 2018, 1:12 PM
KrOW
KrOW - avatar
0
KrOW can't find it there. It's not a Boolean..."private StringListElement first;" "public void append(String string) " https://code.sololearn.com/c8ZKMBW2arLd/?ref=app
15th Nov 2018, 12:47 PM
Sin
0
there are setters and getters given. I have to implement the method.... to get the given string.
15th Nov 2018, 1:09 PM
Sin
0
we can't use this:(
15th Nov 2018, 1:13 PM
Sin
0
We can't use implements... we have to use getString() getNext() getPrev() with nodes etc... but idk how to start I know how to make it with int value but not with strings. KrOW
15th Nov 2018, 1:17 PM
Sin
0
Sin i mean, you know how list data structure works? I understood that you have to implement yourself without use java premade types for this...
15th Nov 2018, 1:20 PM
KrOW
KrOW - avatar
0
KrOW for int data/value yes. for string not really😔😔
15th Nov 2018, 1:21 PM
Sin
0
Sin what you mean with "i know hpw to make it with int but not with strings"?? Whats the problem??
15th Nov 2018, 2:02 PM
KrOW
KrOW - avatar
0
i know how to append given int value at the end of list but Not Strings.. KrOW addlast=append public void append(String string) { StringListElement elem = new StringListElement(); defter.setString(string); if(first==null) { this.first=elem;} else { StringListElement temp=first; while(temp.getNext()!=null) { temp=temp.getNext(); } temp.setNext(elem); } } it says it ist wring
15th Nov 2018, 2:05 PM
Sin
0
elem.setString(string)*
15th Nov 2018, 2:06 PM
Sin