Skott Elliott

Greenhorn
+ Follow
since Nov 25, 2014
Skott likes ...
IntelliJ IDE Chrome Windows
Kiev, Ukraine
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
26
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Skott Elliott

Sorry for not getting back in a timely fashion.  It was an action packed week.  I had a review of my internship and was told that I was going to be released due to slow progress.  (Actually, there is a lot of progress, but coming from no programming at all, they need folks who can step up their game immediately.)  Instead, I've been put on a more individual year-long program.  So, ain't throwing in the towel by any means!

I will definitely get to your post soon Mr. Campbell.  I appreciate a lot the posts you're making for me.  
4 years ago

Campbell Ritchie wrote:

Skott Elliott wrote:. . .   I see you get a lot of inane posts like this from others.  . . .

There is nothing inane about your post; I was considering reporting it to the other mods as an interesting thread. What appears to have happened is that you have been given a rather awkward additional requirement, to remove elements from the current List without creating a new List. That is probably done to make the task more challenging and see how you handle it. They are probably only being awkward like that so as to see how good you are

What is Timer? Is it an app to time your execution time? If so, why do those methods appear to be static?
You appear to have used caps lock in line 1
Why have you changed from Strings to Integers?
How are you populating your List? That would be interesting to see. I have my own ideas about how to populate a List<Integer>.
What do you know about for and while loops for Lists? What do you know about their performance? There are all sorts of interesting things you can find out there, and you can do that all in about 20 minutes of you look in the right place.
Why are you iterating your loop backwards? Why have you written > 1 in the loop? Why are you catching the out of bounds Exception? Do you know how to write a for loop so you can never get an out of bounds Exception?



It's a learning experience.  I walked into this internship with 0 programming or computer science experience.  Obviously I've been on a PC and using Internet since... I think it was 1996 or so.  Learning to program has been a longtime ambition of mine.  

Timer, this is just new Date(), I put it into a separate method because I was tired of copy-pasting it.  I have the method to start, end, and show the results of the new Date().
I think you're right about the caps lock.    
I changed to Integers for no real reason.  The truth is that I forgot that I was working with Strings, had accidental made an iteration with Integer, so I ran with it.

Population of the List is this method here:



The other questions you asked are precisely what I'm hunting for now, as I think part of this exercise was to learn these important bits of the Collections classes.  

Iterating the loop backwards so that there is always an index and won't actually have an IndexOutOfBounds exception.  Catching it because before that I kept running into the exception and it was annoying me, so I put a try-catch phrase to at least have a successful bit of code to look at instead of red text.  It doesn't need to be there now that it works.  i > 1... you got me. Probably should have wrote that as i >= 0.

For the last question, I don't know how to do that.  I'd be all ears.  Could I find that specific information in the Oracle docs?  
4 years ago
I hear you guys.  I see you get a lot of inane posts like this from others.  It's clear that for the internship they want me to do these kinds of exercises.  Today everything was good, but still was asked to use the Map with a for loop without using an Iterator.  I kept getting the IndexOutOfBounds exception, turns out that I just had to change my looping arguments.  Here is what I came up with:



I've been struggling how to explain the why behind the way it works here and how it wouldn't work if we used the "normal" arguments in an for loop.  I'm going to type how I'm able to explain it, maybe somebody else can help clean up my verbose attempt.  Basically, if we do something like:



We are going to carry on to the original end of the ArrayList, which is impossible since elements are being removed, so the list is getting shorter.  Hence IndexOutOfBounds Exception.  But by doing:


We set int i to the last index of the Array List on each iteration, and then we decrease the iteration cycle with i--.  

Do I properly understand this?
4 years ago

Campbell Ritchie wrote:Why do you need the remove method?
What you can do is put all the elements of your List as Keys into the Map, and use a dummy object as a Value. You can actually use the same instance for the Value for every pair. If you go through the code for HashSet, you will find that is how it is implemented. Then you can iterate the Key set in the Map and put everything into another List. If you use a LinkedHashMap rather than an ordinary HashMap, you should get the order of insertion maintained in your new List. You may need some condition like:-
if (!myMap.containsKey(myList.get(123))) ...
Don't copy and paste that code.
Go through the documentation for those different kinds of Map and see what it says, and the Java™ Tutorials.



Yessir, however what I was asked to do was to specifically use the map as a way to remove elements from the ArrayList.  That's what the mentor asked me to do.  On Friday I had simply created a new map which contained unique values by default of how it works, and that was not acceptable.  (Remember, I'm in an internship.) HOWEVER - I do appreciate all the help and tips.  
4 years ago

Knute Snortum wrote:Big Hint: what happens if the key value is already present?



I understand that the keys cannot be duplicated - so in that essence the HashMap removes duplicates.  I'm currently trying to work out how to use the HashMap in a way to remove duplicates from the ArrayList.  I'm almost positive I need to use the Iterator .remove method in a loop.  I just haven't worked it out yet.

*EDIT*

Got it!

4 years ago
Just wanted to give a bit of an update.  I ended up using a LinkedHashSet, a method with a nested loop, and an iterator.  All went fine.  I've been asked to do the same procedure but instead of Set, to use Map.  (HashMap)  So I'm thinking these are just thinking exercises to get used to working with Collections.

The LinkedHashMap:


The Nested Loop Method:


I ended up just populating an ArrayList with a for loop, using 1E5 to make 100,000 random numbers 0 to 100.  (Used new Random();)  I used new Date().getTime() to track the performance, and the Iterator beat out the LinkedHashSet by a few milliseconds in my example every time.  The nested loop wasn't even a close 3rd.

So I'll continue to see how I can accomplish this with a HashMap.  The mentor who gave me this task, it turns out that this was coding example he was asked to complete during the interview he had.  (Aside from a billion questions asked.)  It's certainly a case of 'the more I learn, the more I realise I don't know.'  But it's a good and interesting experience.

*EDIT*
So I realized that the the Iterator didn't work, because when it iterated, it actually didn't find any duplicate values based on how I wrote it.  Seems I have to look into recursion.  For now, working with the HashMap, I'm about 50% of the way I think.



So now I need to see about iterating with the map and ArrayList?  I think I understand a way to do this, just have to hammer it out.  Maybe something like a for each testing for equality of each object's value?  Just thinking out loud.
4 years ago

Campbell Ritchie wrote:

Skott Elliott wrote:. . . a never ending black hole. . . . I'm not sure if this is a clue of things to experiment with, or if it's how I should track which is most efficient.

It isn't a black hole at all, but an opportunity to rise to the challenge. You must acknowledge all suggestions given here. How you do that depends on how formal they want you to be about the problem. You can now create yourself a List with millions of words in. Download a text‑only version of the Bible, War and Peace, Complete Works of Shakespeare or similar from Project Gutenberg and read every word into your List. Go through all the algorithms and work out which run in linear time, which quadratic and which nlogn complexity. Write down your reasoning for all those. Find out how to time the execution of your algorithms, and also how to trick the JIT compiler into getting to full speed before you start your timings. Find out how many of those techniques can be parallelised to take advantage of multi‑core processors. Find out whether the fastest technique is different for a 1000000‑word collection and a 20‑word collection.

Now you will be busy for the next four hours doing all that and writing it down. If what you write is any good, post it here for us to admire.

. . . litre of water and cup of tea and have a think.

You will need more than tea and water

Thanks for all the help and replies . . .

That's a pleasure
Learning the language is easy, but programming is renowned for being a difficult activity.



I did mean the mention of 'black hole' in the nicest way possible.  In fact, it's what keeps me continuously interested.  It's similar to audio recording and production.  You can learn the theory of EQ, but every waveform you record is different and requires different treatment.  No wave form is ever the same - kind of like no boiler-plate code will cover all bases for a solution.  Thank you for the idea of reading in some text, because I already was using System.nanoTime() for these extremely small ArrayLists.  I ended up writing another utilising Iterator with .remove().  Consequently, the LinkedHashSet is the slowest, with the nested loop method being the fastest.  I'm going to implement the huge text file and run these tests again.

Thanks again everybody in the thread that has helped out and has exercised patience with a n00b!
4 years ago

Campbell Ritchie wrote:Are you supposed to produce lots of different ways to remove duplicates, or find the most elegant way.



Coming into the office today and showing what I had, now I'm tasked with getting the most effective/efficient way of doing this in an ArrayList; a way that would use the least amount of operations. What seemed kind of open-and-close yesterday has turned into a bit of a never ending black hole.  They mentioned to pay attention to:

  • compareTo()
  • .remove
  • for each
  • for


  • I'm not sure if this is a clue of things to experiment with, or if it's how I should track which is most efficient.  Anyway, off to get my litre of water and cup of tea and have a think.  Thanks for all the help and replies from everybody else, it's been great food for thought.  I've taught myself music, guitar, drums, orchestral scoring and computers, but damn if programming hasn't given me the biggest fit.
    4 years ago
    Just wanted to update.  So far, I've got three total ways I've coded.

    1) Using a LinkedHashMap;
    2) Using a nested loop that was written for the specific ArrayList;
    3) Using a method removeDuplicates() that was made more generic so it could accept any ArrayList of any type;

    I've been thinking about Fred's post where I could have a method of any Collection type, but haven't figured that out yet.  So I've been able to come up with three ways thus far.  

    For anybody who wants to see, the code is in the following:



    Predictably, the outcome of the code:

    4 years ago
    Hi all,

    I'm at an internship and I've been here for 3 months.  I started with zero Java skills.  Things are going along and I'm able to find most things via Google.  However, this particular task I was given is starting to get the best of me.  The task I have:

    1) You have an ArrayList that contains duplicate string values.  Think of possible ways to remove the duplicates and mark the advantages and disadvantages of each approach.

    Obviously, we can use the HashSet class, which I already have written a bit of code to demonstrate.  (As well as the advantages/disadvantages.)  Now, what the heck else could I use to accomplish this task?

    I'd be grateful for anybody who could point me to the right direction.  I know it's the JavaRanch way to not just give the answer and I'm OK with that.  But a bit of a point in the right direction would be great, be that a point to websites, chapters in a book, etc.  

    Thank you!
    Scott
    4 years ago

    J. Kevin Robbins wrote:It does sound interesting. I strongly suggest that use the jQuery framework. The plugin jQuery UI has a tooltip feature that might work, but you might also want to check out this very impressive tooltip plugin, also for jQuery. That page for tooltipster also has a demo that you might find relevant to your project.



    Aw, this is fantastic. This is really, really helpful.

    Perhaps another n00b question - is it possible to have tooltips in Javadoc format (i.e. Returned type and parameters description)? Looking at the page and messing with it, seems easy to implement the actual jQuery and change around the CSS/HTML. Very good suggestion, thank you!
    Hey guys,

    I'm new here and also relatively new to coding. I'm not a completely n00b, I've had C++ courses and am actively working through Java right now. A project kind of fell into my lap that I decided to take because it's a challenge and something that I think I could accomplish. I'll try to be brief:

    1. The project is re-creating a UI production. There will be screenshots of every page.
    2. Every part of the UI that is clickable and has calls, stored processes, etc., should be clickable. Once clicked, a tool-tip should appear with information inside describing the name of the UI element, all processes called, stored procedures, etc.
    3. If possible, the information should be in Javadoc form.
    4. I also need to formulate a way to make it so that one click = tool-tip, double click = navigate to that specific module page.

    It really sounds complicated, but I believe it's a lot simpler than how I'm describing it.

    I already can handle the HTML5 and CSS3 with my eyes closed. I did a trial run using intro.js. While it looked cool, it was limiting in that the tool-tips went in sequential order, you couldn't click on them, and there was no way to alter it without altering the code itself.

    I am kindly asking anybody here if they've ever had such a project, or could point a lead at code I could look at as an example to help kick me off.

    Thanks!