Results 1 to 4 of 4
  1. #1
    gayathrikven is offline Member
    Join Date
    Dec 2012
    Posts
    7
    Rep Power
    0

    Default Collection class

    How to write a Java method that stores the months of the year and the number of days of the corresponding month in a collection class, then goes through the collection and prints the name of the months that only have 30 days

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: Collection class

    In this forum we are not providing a help to write code. But, we are happily help to guide you if you have any problems with your code. So, please write the code and tell us where you got stuck with it.

  3. #3
    gayathrikven is offline Member
    Join Date
    Dec 2012
    Posts
    7
    Rep Power
    0

    Default Re: Collection class

    import java.util.*;
    Im a newbie to Java, So im learning able these concepts. Im struck at how to list which months have 30days and which have 31days and which have 28days and also how to print that has only 30days

    Im happy to learn but I dont have proper resources to learn, so seeking help
    public class CollectionTest {
    public static void main(String [] args) {
    System.out.println( "Collection Example!\n" );
    int size;
    HashSet collection = new HashSet ();
    String str1 = "Jan", str2 = "Feb", str3 =
    "Mar", str4 = "Apr", String str5 = "May", str6 = "June", str7 =
    "July", str8 = "Aug",String str9 = "Sep", str10 = "Oct", str11 =
    "Nov", str12 = "Dec";
    Iterator iterator;
    collection.add(str1);
    collection.add(str2);
    collection.add(str3);
    collection.add(str4);
    collection.add(str5);
    collection.add(str6);
    collection.add(str7);
    collection.add(str8);
    collection.add(str9);
    collection.add(str10);
    collection.add(str11);
    collection.add(str12);
    System.out.print("Collection data: ");
    iterator = collection.iterator();
    while (iterator.hasNext()){
    System.out.print(iterator.next() + " ");
    }
    System.out.println();
    }

  4. #4
    gayathrikven is offline Member
    Join Date
    Dec 2012
    Posts
    7
    Rep Power
    0

Similar Threads

  1. Replies: 7
    Last Post: 09-07-2011, 07:24 AM
  2. Collections, Collection From one class to another
    By D.Calladine in forum New To Java
    Replies: 2
    Last Post: 11-23-2010, 02:10 PM
  3. Collections, Collection From one class to another
    By D.Calladine in forum New To Java
    Replies: 2
    Last Post: 11-16-2010, 03:39 PM
  4. collection class in java
    By katturv in forum New To Java
    Replies: 5
    Last Post: 10-24-2010, 07:09 PM
  5. know the class coming under the collection api in java
    By javastuden in forum New To Java
    Replies: 1
    Last Post: 11-24-2009, 07:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •