Having trouble removing duplicates from list

Hello
I am strugling with this
I have a ArrayList as i am adding stuff in it i want to make sure i am adding just the Unique stuff. I am adding objects of class paper in the list. paper class has an attribute called color. so i have overwritten the equals method of paper class like this
public boolean equals(Object other)
if (!(other instanceof paper)
    return false;
paper detTo = (paper) other;
          return detTo.getColor().equalsIgnoreCase(this.getColor());
}while I am adding stuff to the list i am doing this
List onlyColor = new ArrayList();
while (li.hasNext())
paper p1 = (paper) li.next();
if (!onlyColor.equals(p1)) //only add when equals returns false?
   onlyColor.add(p1);
   System.out.println("Adding: " + p1.getColor());
}but it is still adding duplicate stuff in the list (onlyColor). what am i doing wrong!? i heard that i should overwrite the hashcode as well...but how can i do it..can anyone help? Also does it matter that class paper is extending another class called utilities. and getColor() attribute is actually in the utilities class..?
Thanks! please help me solve this :(
Message was edited by:
Omnipresent
also, if i chance the equals method to always return true by default
public boolean equals(Object other)
if (!(other instanceof paper)
    return false;
paper detTo = (paper) other;
          return true;
}and then change
if (!onlyColor.equals(p1)) to
if (onlyColor.equals(p1)) nothing is being added to the list!! i am suspicious if my overwritten equals method is even called!!?!?

i am planning to get this book
http://www.amazon.com/Certified-Programmer-310-055-Certification-Guides/dp/0072253606
have u come across this one before?
if i go thru this..do u you think i'll be uptodate
with java5?That's what the goal of that book: getting you ready for a Java 5 certification. Personally I'd start with a decent Java book like this one: http://www.sun.com/books/catalog/gosling_JPL4.xml
and perhaps a data structures and algorithms book.
After that, buy yourself a certification book to see what's important to know when taking an exam.
A certification book will not make you a good programmer. Don't get me wrong: a decent Java book won't make you a good programmer over night either, but it's (IMO) a better basis to learn the language than a certification book.

Similar Messages

  • I am having trouble removing songs from my iPhone.  i have unchecked songs in the library on my mac, but they still show up on phone after syncing.  how do I remove them?

    I am having trouble removing songs from my iPhone.  i have unchecked songs in the library on my mac, but they still show up on phone after syncing.  how do I remove them?

    Hi asims01,
    Welcome to the Support Communities!
    The information below may be able to answer your questions about how to delete songs from your iPhone:
    Deleting songs downloaded to your device
    Tap the Music app.
    Tap More > Songs at the bottom.
    Scroll or search for the song you would like to delete from your device.
    Swipe right to left on the song, and then tap Delete.
    Note: You must be in Artists, Songs, or Albums view to delete songs from your device. Deleting from a playlist won't remove a song from your iOS device.
    Also, this information can be found on page 64 of the iPhone User Guide for iOS 7
    http://manuals.info.apple.com/MANUALS/1000/MA1565/en_US/iphone_user_guide.pdf
    Remove a song from iPhone. Tap Songs, swipe the song, then tap Delete. The song is deleted from iPhone, but not from your iTunes library on your Mac or PC, or from iCloud.
    If you have iOS 7, this will delete the song from local storage, but the song will still appear with a cloud symbol in the Music app, as you've noticed. To hide the iTunes in the Cloud purchases, navigate to Settings > iTunes & App Store, and disable "Show All: Music”
    There may be a few orphaned songs on your iPhone that were partially downloaded or corrupted in some way. If that is the case, you can erase all of the music from your phone.  Follow the instructions below and select the Music app under Usage:
    iPhone, iPad, and iPod: Understanding capacity
    http://support.apple.com/kb/ht1867
    I hope this information helps ....
    - Judy

  • Having trouble removing traits from a media element

    I am having difficulty removing a trait from a subclass of the LightweightVideoElement.  Depending on the type of video playing through the netstream, I want to remove the seek trait to prevent seeking with the chrome scrub bar.
    My problem is that when I remove the trait from the element the hasTrait method is still returning true.  To demonstrate I add a listener in my element's constructor like so:
    addEventListener(MediaElementEvent.TRAIT_REMOVE,announceTraitRemoved);
    And my function is:
    private function announceTraitRemoved(e:MediaElementEvent):void
                trace("Element --> announceTraitRemoved --> TRAIT REMOVED: "+e.traitType + " so hasTrait: "+hasTrait(e.traitType));
    The output of the function after calling removeTrait(MediaTraitType.SEEK) is:
    Element --> announceTraitRemoved --> TRAIT REMOVED: seek so hasTrait: true
    It never returns hasTrait: false for the seek trait.
    This is problematic because the chrome package ScrubBar determines if the scrubber is enabled by listening to this event in a similar fashion and using the hasTrait method, so I cannot figure out how to disable the scrub bar.
    What am I doing wrong?  If it matters, I am using 1.0gm.
    Thanks.

    Okay that makes sense.  I didn't realize the event was fired ahead of time because some of the traits were returning false for the function... but I guess it just happened to be a timing thing from being removed and added and such.
    For this case, the custom netstream "knows" if seeking is possible and skips the actual seeking part of the seek call and only dispatches events if seeking is not allowed, so I am not actually worried about the SeekTrait exactly.  I want to convey to the user that the video cannot be seeked through by "greying" out the scrubber.
    From what I understand the proxy element would just stop the seek event from hitting the netstream and would not trigger the ScrubBar to grey out the scrubber.
    How does one signal to the ScrubBar that the scrubber should be disabled?  This is the check that the chrome package ScrubBar uses when traits are added or removed:
    scrubber.enabled = media ? media.hasTrait(MediaTraitType.SEEK) : false;
    Do I have to remove the seek trait and then toggle another trait?

  • JList run time errors when removing items from list

    Hi there
    I am having trouble removing items from a JList. For a While it was working fine and now it outputs runtime errors everytime samething gets removed from the lsit
    Here is the code
    //declare
    public class Consumertab1gui extends JPanel implements ActionListener
         public static JList conList = null;
         private static DefaultListModel model = null;
    // Create a list with some items
    model = new DefaultListModel();
    conList = new JList(model);
    //set the size of cells in the list with the length of the string
    conList.setPrototypeCellValue("Lenght 1234567890");
    conList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    conList.addListSelectionListener(new ValueReporter());
    //set a scroll onto the list
    JScrollPane conScroll = new JScrollPane(conList);
    add(conScroll,c);
    //when the button gets pressed to drop the selected item the following code is called
    private void dropConsumer()
    int selItem=0;
    componentsV.comVRemove(conList.getSelectedValue().toString());
    selItem=conList.getSelectedIndex();
    System.out.println("No:"+(model.getSize()-1));
    System.out.println("S:"+selItem);
    remConList(selItem);
    dropCon.setEnabled(false);
    //which in turns calls this
    public void remConList(int pos)
         model.remove(pos);
    when the model.remove(pos) code is executed the following runtime errors are given:
    java.lang.NullPointerException
    at Consumertab1gui$ValueReporter.valueChanged(Consumertab1gui.java:197)
    at javax.swing.JList.fireSelectionValueChanged(JList.java:1321)
    at javax.swing.JList$ListSelectionHandler.valueChanged(JList.java:1335)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:187)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:167)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:214)
    at javax.swing.DefaultListSelectionModel.removeIndexInterval(DefaultListSelectionModel.java:546)
    at javax.swing.plaf.basic.BasicListUI$ListDataHandler.intervalRemoved(BasicListUI.java:1561)
    at javax.swing.AbstractListModel.fireIntervalRemoved(AbstractListModel.java:160)
    at javax.swing.DefaultListModel.remove(DefaultListModel.java:478)
    at Consumertab1gui.remConList(Consumertab1gui.java:38)
    at Consumertab1gui.dropConsumer(Consumertab1gui.java:58)
    at Consumertab1gui.actionPerformed(Consumertab1gui.java:46)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
    at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
    at java.awt.Component.processMouseEvent(Component.java:5100)
    at java.awt.Component.processEvent(Component.java:4897)
    at java.awt.Container.processEvent(Container.java:1569)
    at java.awt.Component.dispatchEventImpl(Component.java:3615)
    at java.awt.Container.dispatchEventImpl(Container.java:1627)
    at java.awt.Component.dispatchEvent(Component.java:3477)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
    at java.awt.Container.dispatchEventImpl(Container.java:1613)
    at java.awt.Window.dispatchEventImpl(Window.java:1606)
    at java.awt.Component.dispatchEvent(Component.java:3477)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
    can anyone spot any mistakes in the code or suggest possible resons as to why these run time errors occur?
    Thanks
    alexis

    java.lang.NullPointerException
    at Consumertab1gui$ValueReporter.valueChanged(Consumertab1gui.java:197)The NullPointerException occurs at line 197, in the valueChanged method of your ValueReporter inner class. I have looked through your post several times but I don't see where you posted that method. Anyway, that is where you should look.
    PC²

  • Trouble removing photos from iPad

    I'm having trouble removing photos from my iPad2 running iOS 5.0.1. In iTunes I've told it not to sync ANY photos. When I first changed this it asked me if I wanted to remove the photos currently there, I said yes and they disappeared. But when it finished syncing they had reappeared despite the fact that it now claims I don't have it set to sync any photos. I don't have photostream enabled. I've tried syncing a couple of times, but no luck. Any ideas? (I searched the forums but everything I found was people who didn't understand how to use iTunes to manage iPad content...that's not my problem..) (also it is like 3 gigs of pics so I don't really want to delete them all by hand since there isn't a way to batch delete...)

    Try deleting the photo cache from your computer and then select and sync an empty folder to the iPad and see if that removes them - the location of the cache, and how to delete it, is on this page http://support.apple.com/kb/TS1314

  • Removes duplicates from a sorted array without having to create a new array

    Funcation removes duplicates from a sorted array without having to create a new array

    Funcation removes duplicates from a sorted array
    without having to create a new arrayIs a 'funcation' like a vacation but more fun or
    something?LMFAO. You just jumped with both feet on one of my biggest peeves. I've been outed!
    Actual words/phrases I've seen used which I hate with every fiber of my being:
    "Mrs. Freshly's"
    "McFlurry"
    "Freshissimo"
    "Spee-dee"
    "Moons Over My Hammy"
    One of my favorite SNL skits had Will Ferrell leading a panel of movie reviewers (they're the worst for this kind of junk). Each one had some cheesy pun to describe their respective movie. Ferrell topped the show off with his endorsement of "Fantasia 2000 is Fantasgreat!"
    LOL.
    "Come to Slippy Village - it's a FUNCATION!"
    § (runs off, laughing maniacally, head explodes)

  • I'm having trouble importing pictures from the internet....when I drag the picture to the icon, it gives me the option to import all duplicates. Even when I click "NO", it STILL imports every picture I have imported AGAIN, including the new one! WHY??

    I'm having trouble importing pictures from the internet....when I drag the picture to the icon, it gives me the option to import all duplicates. Even when I click "NO", it STILL imports every picture I have imported AGAIN, including the new one! WHY??

    carolinechx wrote:
    i know the description may be a little bit too confusing
    Mostly because you are not using any capital letters or paragraph returns and your post is difficult to read.

  • TS3212 I am told that the ITunes will not download because it is having trouble removing the older version bonjour. What do I need to do?

    I am trying to sync my new IPhone 4 with ITunes. I have tried downloading the new version of ITunes on my pc like it told me to do but it stops in the middle of downloading and says that it is having trouble removing the old bonjour. It said I should contact support. What do I need to do?

    Download the Windows Installer CleanUp utility from the following page (use one of the links under the "DOWNLOAD LOCATIONS" thingy on the Major Geeks page):
    http://majorgeeks.com/download.php?det=4459
    To install the utility, doubleclick the msicuu2.exe file you downloaded.
    Now run the utility ("Start > All Programs > Windows Install Clean Up"). In the list of programs that appears in CleanUp, select any Bonjour entries and click "Remove", as per the following screenshot:
    Quit out of CleanUp, restart the PC and try another install. Does it go through this time?

  • Hi I am having problems removing mail from trash folder. Can anyone help please

    Hi I am having problems removing mail from trash folder. I can send mails to the folder but cannot delete them permanently from the trash folder. I am using Iphone 3G and anm up to date with OS. Can anyone help please

    Check that there isn't a different Trash folder to the one with the proper Trash symbol on it.
    If you see one in your list of folders rather than a separate one, highlight it, then click on Mailbox...Use this mailbox for...Trash

  • Since downloading iOS 7, I have been having trouble purchasing music from iTunes Store. When ever I try to make a purchase I always get the message "Your account    is not valid in the US  store"

    Since downloading iOS 7, I have been having trouble purchasing music from iTunes Store. When ever I try to make a purchase I always get the message "Your account    is not valid in the US  store" As I am new at this I don't know what I can do to remove this problem.

    What country are you in ? If you aren't in the US and the address on your account isn't in the US then try going to the bottom of the Featured tab in the App Store app on your iPad and tap on your account id, tap on 'View Apple ID' on the popup and log into your account, and then select the Country/Region section and select your country.

  • I am having trouble removing/changing my iphone id. It keeps reverting back to my partners id any help would be appreciated.

    I am having trouble removing/changing my iphone id. It keeps reverting back to its previous id. How can I fix this problem?

    Jgreg14 you have my sympathies. 36 hours ago while using my iPad I was told that my Apple ID had been disabled. Like you I went to the forums, reset my password, and also like you, nothing changed. I have contacted iTunes support and after 24 hours they responded with this:
    Cesar here from the iTunes Store Support Team. Your inquiry is very important to me, so I have requested assistance with the issue you reported. You will receive an email after the matter has been investigated and further information is available.
    Thank you for your patience. Apple wants your iTunes experience to be as enjoyable as possible. Take care!
    Boy do I feel special. I sat on the phone to the UK helpline for 30 minutes, and have been told my case has been elevated to "URGENT".
    Basically I was wondering if you ever got your problem sorted out?

  • Best app to remove duplicates from iTunes 2014

    Hi All,
    I've been trying to research the best application to sort and remove duplicates from my iTunes library. I have over 7000 songs and iTunes built in duplicate finder doesn't look at the track fingerprint, which is useful for those songs which are labelled "Track_1" etc.
    Has anyone reviewed any recent products? I was looking at TuneUp, but after reading so many negative comments, I've decided not to go down that path. I would prefer a program that did most of the work for me, due to the amount of songs. Happy to pay for a good product...
    I do have MusicBrainz Picard, which has done a great job of tagging, but don't remove duplicates.
    Thanks in advance :-)

    Tune up is a great app.  When they moved from version 2 to version 3 is when it went to crap and all heck broke loose.  They shut their doors  but they have since re opened and went back to developing  version 2.  I use that version and I am pretty happy with it as being an overall cleanup utility.  I also use Musicbrainz and a couple of other utilities but in the end if you have an enormous library 20k plus then you are going to have a few slip through.  I would probably go with Tuneup if I were you and a thorough third party duplicate finder.  Dupe Guru's music edition seems to do a pretty good job.

  • I am having trouble transferring files from an old MacBook (2007) to a MacBook Air over a wireless network.  The connection was interrupted and the time was over 24 hours.  Is there a better way to do this?  I'm using Migration assistant.

    I am having trouble transferring files from an old MacBook (2007) to a MacBook Air over a wireless network.  The connection was interrupted and the time was over 24 hours.  Is there a better way to do this?  I'm using Migration assistant.  The lack of an ethernet port on MacBook air does not help.

    William ..
    Alternative data transfer methods suggested here > OS X: How to migrate data from another Mac using Mavericks

  • HT2905 i have just followed all the insrtuctions in support to remove duplicates from my library but now most of my musicis gone except for my recent purchases. How come and how do i fix it?

    i have just followed all the instructions in support to remove duplicates from my library but now most of my music is gone except for my recent purchases. How come and how do i fix it?

    Final Cut is a separate, higher end video editor.  The pro version of iMovie.
    Give iPhoto a look at for creating the slideshow.  It's easy to assemble the photos in an album in iPhoto, put them in the order you want and then make a slideshow of them.  You can select from various themes and transitions between slides and add music from your iTunes library.
    When you have the slidshow as you want use the Export button at the bottom of the iPhoto window and export with Size = Medium or Large.
    Save the resulting Quicktime movie file in your Movies folder.
    Next, open iDVD, choose your theme and drag the QT movie file into the menu window being careful to avoid any drop zones.
    Then follow this workflow to help assure the best qualty video DVD:
    Once you have the project as you want it save it as a disk image via the File ➙ Save as Disk Image  menu option. This will separate the encoding process from the burn process. 
    To check the encoding mount the disk image, launch DVD Player and play it.  If it plays OK with DVD Player the encoding is good.
    Then burn to disk with Disk Utility or Toast at the slowest speed available (2x-4x) to assure the best burn quality.  Always use top quality media:  Verbatim, Maxell or Taiyo Yuden DVD-R are the most recommended in these forums.
    The reason I suggest iPhoto is that I find it much easier to use than iMovie (except for the older iMovie 6 HD version).  Personal preferences showing here.

  • Having trouble streaming hulu, from Ipod Touch, to my TV, using Apple A/V cable

    Having trouble streaming hulu, from Ipod Touch, to my TV, using Apple A/V cable?

    Safari will not display TV out and neither will the Hulu plus app.

Maybe you are looking for

  • Restrict no. of connections to DB

    Guys, I have a scenario like 'App Module A' pool cant use more than specified no. (say N) of DB connections. But there may be more than N instances requried at a time. How this can be acheived? (using passivation it should be possible) what is the co

  • Excel - Unrecogniz​ed Document Format...N​OT a Office 2007 issue

    On my previous, and now latest BB (8330), I cannot open e-mail attachments in the Excel (.xls) format. I am using Access 2003 to produce reports/exceptions/alerts using Office 2003 (and Excel 2003 as well). It's no issue on a standard PC...the attach

  • Sharpen image in Photoshop cs4

    A co-worker had a TV stolen and I am trying to help her by sharpening an picture of the serial number on the back but I can't seem to sharpen it enough to read the numbers on the back using the unsharp mask.

  • Whenever I try to open a PDF, the window closes 5 seconds later.

    Reader is malfunctioning on my computer. Whenever I try to open a PDF, the window closes 5 seconds later. This all started a few days ago when I tried updating the version of Reader I had. Since then I've had multiple problems or either not being abl

  • Apologies, this item has been interrupted due to an error...

    Hi there. Recently i have changed motherboards/processors in my desktop PC (but kept the same hard drive). Since then, when i go to view Sky Go on my desktop, i get the following error message: "Apologies, this item has been interrupted due to an err