Forums Register Login

Java arraylists search and replace elements in each list

+Pie Number of slices to send: Send
I have lists in an arraylist(2 dimensional), elements are recurrent in lists. I would like to search for a specified element and replace the second element after it in all the lists.



Example - I search for 154 and 358, so zeros should be changed to 1:

[288, 362, 0, 365, 85, 0, 137, 10, 0, 154, 358, 1]

[285, 226, 0, 137, 10, 0, 20, 30, 1, 387, 297, 0, 154, 358, 1]



This code do it only for one match, not for all matches.
+Pie Number of slices to send: Send
Sorry didn't understand well. Could you please explain more and also how do you define "lists in an arraylist(2 dimensional)" ?
+Pie Number of slices to send: Send
There is a "big" list, which each elements are another lists.
+Pie Number of slices to send: Send
Ok so you are using List of list.

Also did not understand why in second for loop you are incrementing by 3? What is 'h' in if condition?

So it is better if you could explain little bit more.
+Pie Number of slices to send: Send
In every iteration are number, number+1, number +2 indexes. Incrementing +3 should make it possible not to examine 1 number twice.
+Pie Number of slices to send: Send
hi Kovacs,

Is this still part of your work on adjacency lists?
If so, why dont you use Points? That will make your code
really very much easier to make and understand. I refer you to
this topic:

https://coderanch.com/t/647964/java/java/Arraylists-arraylist-representation-relationships

If I look at these topics:

https://coderanch.com/t/649061/java/java/Special-array-pop

and

https://coderanch.com/t/648997/java/java/Adjacency-lists-Java

I think the code as presented there is quite hard to follow, and therefore
quite hard to debug.

You started with a list containing all the edges, in textform:

x1 250 y1 300 x2 0 y2 50
(...)


So, lets say you were able to create, from your initial list, the
HashMap<Point, ArrayList<Point>>.

Can you tell us what it is that you are trying to achieve? Things
that come to my mind are:

1) finding out if there is a path between Points p1 and p2
2) if so, find the shortest path
3) how many times is Point p the second point of an edge? (this frequency
has a name, but I forgot)
4) create an adjacency matrix from the map

et cetera.

So, what are you trying to achieve here?

Greetz,
Piet

For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 605 times.
Similar Threads
Circular motion applet
Need help on animation using GUI Builder.
how to update the edited data in textfield to table in java
http connection problem
Pop up calendar Problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:58:33.