• 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

Collections API

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Guys,

In order to understand most of the methods in Collections interface,I have downloaded the API's but Im not sure how to make sense of it. Is there a more detailed Collections API tutorial with more examples so I can appreciate the use of each method in it?

Thanks in advance!
[ September 11, 2007: Message edited by: Muni K Reddy ]
 
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is a link from the Sun tutorials:

Sun Tutorial On The Collections Framework

I can't say that I understand it perfectly either, but I would concentrate first on the interfaces and then on the concrete classes that implement the interfaces.

If you don't understand some of it such as what a HashMap and what a LinkedList is, you should study the data structures and algorithms.

Kaydell
[ September 11, 2007: Message edited by: Kaydell Leavitt ]
 
Muni K Reddy
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kaydell Leavitt:
[QB]Here is a link from the Sun tutorials:

Sun Tutorial On The Collections Framework

I can't say that I understand it perfectly either, but I would concentrate first on the interfaces and then on the concrete classes that implement the interfaces.

If you don't understand some of it such as what a HashMap and what a LinkedList is, you should study the data structures and algorithms.

Kaydell

QB]


Thanks for your reply Kaydell! I have actually done that I know the stucture - Collections, Lists, Sets, Maps, SortedMap etc.
I also know which classes implement or extend which interface or class respectively.
I can define a List, Set, Map.
But,, given a problem, I dont know how to browse and find the appropriate method in the Collection API.


For example:

Lets say I have a String like : "Hello Javaranch heLLo JavaRanch".
I would like to do 2 things
  • Reverse the words : "JavaRanch heLLo Javaranch Hello"
  • &, I would like to delete duplicates - so the output is "Javaranch Hello"

  • Please note that the string could be of any length and the method that matches the words has to be case insensitive(i.e heLLO = Hello) and the output should be sentence case like "Javaranch Hello"

    My approach would be to parse the line get the tokens into a String array, convert everything into a small case then put them into a set. and display them in reverse order.


    My question is not necessarily about the solution to above example. How do I find out that the approach I employ is the best one? How do I find out if there is a method in the Collections API which makes my life easier?

    Thanks
    Vivek
     
    Rancher
    Posts: 3742
    16
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    First you have to learn the features of each of the interfaces. Check out the tutorial link above to do this. When you know the features of each interface, you will know which one is best for your needs.
    At this point look at the JavaDoc for the interface you have chosen. This will give you list of all the known implementing classes. You can then choose which of these classes best suits your requirements.

    For example, lets assume you want a collection that is ordered and contains no duplicates.
    Now, from your knowledge of the interfaces, you know that any class that implements the Set interface will not contain any duplicates. So look at the JavaDoc for the Set interface. Near the top of this page is a list of Known SubInterfaces. You want an ordered set - there's a subinterface called SortedSet - that sounds promising. Click on the link. On that page there is a list of implementing classes - ConcurrentSkipListSet and TreeSet. Click on the links for both of those and see which one is best for you.
     
    Kaydell Leavitt
    Ranch Hand
    Posts: 694
    Mac OS X Eclipse IDE Firefox Browser
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I agree with the poster that recommended the SortedSet type.

    To get the String objects to put into the SortedSet, you can split the original String object using the space character as a delimiter. You can use the method of String called split(). I believe that this will give you an array of Strings. Once you have an array of String object, I believe that you can put them into the SortedSet by iterating over the array of String objects in reverse order.

    Best Regards,

    Kaydell
    [ September 12, 2007: Message edited by: Kaydell Leavitt ]
     
    Muni K Reddy
    Ranch Hand
    Posts: 74
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks Joanne and Kaydell !
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic