Posts

Showing posts with the label arraylist

Remove Only One Item from a List (Android)

Image
Clash Royale CLAN TAG #URR8PPP Remove Only One Item from a List (Android) I have a list: (x, y, y,z) (x, y, y,z) I have another list: (x, y) (x, y) You want to remove the items from the 1st list that belong also in the 2nd list. Ex: I want the result to be (y,z) (y,z) How do I do this? EDIT: If I use removeAll. The example list returns (z) You want to remove the items from the 1st list that belong also in the 2nd list. Edit your question. – mTak 7 mins ago Does order matter? For example, if the second list was (y, x) would you want the same outcome? – Tyler V 4 mins ago The result will be (z) not (y,z) – mTak 3 mins ago ...

Leaf to Root Path Java

Image
Clash Royale CLAN TAG #URR8PPP Leaf to Root Path Java I have been searching around but can't seem to understand how to return path from leaf to root. For Example: A / B C / / D E F So if I do A.find(E) it should return [A,C,E] and if I do B.find(D) it should return [B,D] A.find(E) [A,C,E] B.find(D) [B,D] My attempt : // Base Case - The root of this Tree is c. Route is just [child] public List<Person> find(Person c) { List<Person> path = new ArrayList<Person>(); Person p = c; while(c != null) { path.add(p); } return path; } If you want to get to the root you need: while (node.parent != null) {node = node.parent} thats it – yossico 1 hour ago This question is a bit unclear: you ask I... can't seem to understand ...