• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting value of all the indices of all objects from an arraylist

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone
A little help!
I have a scenario where i need to get the index values of some objects present in the array list and if i use indexof() method of arraylist class it returns me only the first found object index but i have duplicate values in it . So it only return me first object index every time but none other. kindly c the code below :-


I am passing x and c dynamically and there values are 10 and 5 respectively:- here is my output

values in list are :- 3032232144
size of array list is 10
item removed is 3 and it's position is 5
item now present on 5 position is 2
now size of array list in 9
values in list are :- 303222144
index of element is 0
total no of duplicated values are 2


*********it only returned index of first 3 present on second last line of output but no other 3's index and i know thet indexof() method returns only first index so is there any way or any other method call that can solve my problem.*************************************

thanks in advance


[HENRY: Added Code Tags]
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A possible option is to iterate through the list. Not very efficient, but then again, the indexOf() method uses loops too.

Henry
 
Ryan Raina
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:A possible option is to iterate through the list. Not very efficient, but then again, the indexOf() method uses loops too.

Henry




I am actually iterating the list and also i have moved this line in if statement of indexFind() method:- System.out.println("index of element is " + q); but output is :-
values in list are :- 3422310020
size of array list is 10
item removed is 1 and it's position is 5
item now present on 5 position is 0
now size of array list in 9
values in list are :- 342230020
index of element is 0
index of element is 0
total no of duplicated values are 2


index of element is still o for both 3 and it sholud be"
index of element is 0
index of element is 4
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can do something like this:

using a new temp variable that is incrementing for each iteration:

 
Ryan Raina
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dragos Nica wrote:You can do something like this:

using a new temp variable that is incrementing for each iteration:




thanks for your reply it worked:)



 
Can you hear that? That's my theme music. I don't know where it comes from. Check under this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic