Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
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
Tim Cooke
paul wheaton
Jeanne Boyarsky
Ron McLeod
Sheriffs:
Paul Clapham
Liutauras Vilda
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Beginning Java
List Duplicated
Shiaber Shaam
Ranch Hand
Posts: 252
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
How to remove duplicates from arraylist without using set or api?
$Hi/\bEr
Campbell Ritchie
Marshal
Posts: 80227
424
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
With a lot of hard work. Think about how you would do it, and tell us your ideas.
Shiaber Shaam
Ranch Hand
Posts: 252
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
i dont want to use sets. but using api like remove method is fine. am still trying. will post if i get succeed.
$Hi/\bEr
Campbell Ritchie
Marshal
Posts: 80227
424
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Good luck with it. If you get part of it right, post what you have and we'll be happy to look at it.
John de Michele
Rancher
Posts: 600
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Shiaber,
I'm curious about why you don't want to use a Set. It seems like the easiest way to go about removing duplicates.
John.
Campbell Ritchie
Marshal
Posts: 80227
424
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
People are sometimes given assignments or exercises which tell them to avoid the easy or obvious way to do things
Shiaber Shaam
Ranch Hand
Posts: 252
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
i didnt want to use sets as i had to do an additional thing while removing duplicates and that cant be done if i remove duplicates using sets. i found some algorithm from net to remove duplicates and enhanced it in the way i wanted.
thanks,
$Hi/\bEr
Campbell Ritchie
Marshal
Posts: 80227
424
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Well done
Please tell us briefly how you did it, then others can learn from your experience.
Shiaber Shaam
Ranch Hand
Posts: 252
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I tried in a different method by removing duplicates in the orig. list. It didnt work. I got the below algorithm from net and changed to my need.
public static void main(String [] args) { List list1 = new ArrayList(); String a = new String("A"); String b = new String("A"); String c = new String("A"); String d = new String("B"); String e = new String("A"); String f = new String("C"); list1.add(a); list1.add(b); list1.add(c); list1.add(d); list1.add(e); list1.add(f); for(int i=0; i <list1.size();i++) { System.out.println("list1contents"+(String)list1.get(i)); } List newList = new ArrayList(); for(int i=0;i<list1.size();i++) { if(!TestListDuplicates.contains(newList, (String)list1.get(i))) { newList.add(list1.get(i)); } } for(int i=0; i ><newList.size();i++) { System.out.println("newListcontents"+(String)newList.get(i)); } } private static boolean contains(List a, String e) { for(int j=0;j<a.size();j++) { if(((String)a.get(j)).equals(e)) { return true; } } return false; }
>
$Hi/\bEr
Something must be done about this. Let's start by reading this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
logic:equal tag not evaluting
help please....
message-resources problem
struts-blank.war
JSP Parse error - no setter method found
More...