• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Collections vs Collections

 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I am confused.
There is a collections class in the main api and a new seperate collections api.
What are the different "terms" for these? One is in the main api, how do you say that. One is an add on library, how do say that?
If I install the new collections api will all my existing collections code still work?
Thanks.
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Christopher,
The java.util.Collection is the parent interface of the collection API.
While the java.util.Collections class is a helper class (mostly static methods) to work with Collections.
Your collections (mainly Vectors) will continue to work after updating to Java 2 collections API.
Regards,
Manfred.
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So the parent interface java.util.Collection is part of the "standard" api.
And the helper class java.util.Collections is an "add on". By "add on" I mean you have to download and install another library. Is that correct?
So when I go to the sun site to look at the api, I select "java.util", than I select "Collections". Now is this the "standard" api only? Where do I find the "add on" api?
This is what I am talking about when I say add on
Thanks.


[This message has been edited by christopher foran (edited November 30, 2001).]
 
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.util.Collections is part of the standard java 2 API. IT could have been refered to as an add on maybe because it is new in java 1.2 and above.
------------------
Bosun
SCJP for the Java� 2 Platform
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using an example from this article (shown below) it was not working and a coworker told me I had to download an add on library to use collections.
But when I changed the include from "java.util.collections.*" to "java.util.*" it started working.
Can anyone clear that up for me? Thanks.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sun did not create a separate directory in their jar structure dedicated to collections. They just mixed them in with the rest of the utils.
You can check out where they live in the API documentation. Just click on Collections or any class that implements Collection and look at the heirarchy.

[This message has been edited by Cindy Glass (edited November 30, 2001).]
 
Sheriff
Posts: 9103
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by christopher foran:
... a coworker told me I had to download an add on library to use collections.

But when I changed the include from "java.util.collections.*" to "java.util.*" it started working.

Can anyone clear that up for me? Thanks.

<pre>
import java.util.* ;
// The java.util package includes (since the 1.2 release) classes that
// implementjava.util.Collection interface


// import java.util.collections.* ;
// There is no package named java.util.collections in the current jdk.
// The code in the article is in error, and your friend is in error.


public class CollectionTest
{

public static void main( String[] args)
{
System.out.println("Collection Test") ;

HashSet collection = new HashSet() ;
// HashSet implements Collection and therefore is a Collection

String dog1 = "Max" ;
String dog2 = "Bailey" ;
String dog2 = "Harriet" ;

collection.add( dog1) ;
// add() is a method in the Collection interface and is
implemented in the HashSet class


collection.add( dog2) ;
collection.add( dog3) ;

System.out.println("Collection created, size = "
+ collection.size() + ", isEmpty = "
// size() is a method in the Collection interface and is
// implemented in the HashSet class


+ collection.isEmpty()) ;
// isEmpty() is a method in the Collection interface and is
// implemented in the HashSet class


System.out.println("Collection contains " + dog3
+ ":" + collection.contains( dog3)) ;
// contains() is a method in the Collection interface and is
// implemented in the HashSet class


System.out.println("Collection iteration (unsorted):") ;
Iterator itor = collection.iterator() ;
// iterator() is a method in the Collection interface and is
// implemented in the HashSet class


while( itor.hasNext())
{
System.out.println(" " + itor.next()) ;
}

collection.remove( dog1) ;
// Likewise
collection.clear() ;
// Likewise
}
}
</pre>



[This message has been edited by Marilyn deQueiroz (edited November 30, 2001).]
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


There is no package named java.util.collections in the current jdk. The code in the article is in error, and your friend is in error.


Ya, I finally figured that out.
With

every thing compiled except for the Iterator. Which is one of the reasons I started down the wrong path. My co-worker and the author of that article being the other two reasons.
Thanks for the help (as always).
 
It wasn't my idea to go to some crazy nightclub in the middle of nowhere. I just wanted to stay home and cuddle with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic