Home Java Example Java Util Java Util Examples List

Related Tutorials


 
 

Share on Google+Share on Google+

Java Util Examples List

Advertisement
The util package or java provides many utility interfaces and classes for easy manipulation of in-memory data.

Java Util Examples List - Util Tutorials

     

The util package or java provides many utility interfaces and classes for easy manipulation of in-memory data. The java util package tutorials  at RoseIndia.net introduces you with the Java util package of JDK. All the examples are with free source code. It includes many examples that demonstrate the syntax and example code of java util package.

  1. What is java.util package?
    Java Utility package is one of the most used packages in the java programming world and package provides many interfaces and classes for easy manipulation of data.
      
  2. Generating a Random Number
    In many places you need random numbers to fulfill your requirements. Java provides classes to help you in generation random numbers for your application.
         
  3. Breaking a String into Words
    In this section, you will learn how to break the string into words. The java.util.*; package provides you a simple method to breaking the string into separate words.
      
  4. Listing All Available Locales
    Locale is the class of java.util.*; package. This class represents the geographical, political and cultural region. Every tasks which requires to perform the operation is called local-sensitive.
        
  5. Setting the Default Locale
    This section shows you how to set the default locale. Example presented in the section, illustrates you how to get and set the default locale.
        
  6. Associating a Value with an Object
    In this section, you will learn how to associate value with an object in Java util. Here, you will know how to associate the value for the separate code. Values regarding to the separate code are maintained as a record of the specific person. 
        
  7. Comparing Arrays
    This section show you how to determine the given arrays are same or not. The given program illustrates you how to compare arrays according to the content of the that.
         
  8. Shuffling the Elements of a List or Array
    Shuffling is the technique i.e. used to randomize the list or array to prepare each and every element for the operation. In this section, you will learn about shuffling the element of a list or array.
      
  9. What is Collection Framework?
    Java provides the Collections Framework. In the Collection Framework, a collection represents the group of the objects. And a collection framework is the unified architecture that represent and manipulate collections.
        
  10. Iterate Collection
    In this Example you will learn how to iterate collection in java. A running example of java program is provided that shows you how you can iterate collections in java.
     
  11. Java next()
    In this section, you will get the detailed explanation about the next() method of interface Iterator. We are going to use next() method of interface Iterator in Java.
  12. Java remove()
    In this section, you will get the detailed explanation about the remove() method of interface Iterator. We are going to use remove() method of interface Iterator in Java.

  13. Java nextElement()  
    In this section, you will get the detailed explanation about the nextElement() method of interface Enumeration. We are going to use nextElement() method of interface Enumeration in Java.

  14. Java hasMoreElement()
    In this section, you will get the detailed explanation about the
    hasMoreElement() method of interface Enumeration. We are going to use hasMoreElement() method of interface Enumeration in Java.

  15. Converting a Collection to an Array
    Here is the illustration for the conversion from the collection to an array. In this section, you will learn how to do this.
      
  16. Converting an Array to a Collection
    Here is the illustration for the conversion from the an array to a collection. In this section, you will learn how how to do this. The given example gives you a brief introduction for converting an array to collection without losing any data or element held by the array.
        
  17. Collection to Array
    The example given below illustrates the conversion of  a collection into a array. In this example we creating an object of ArrayList, adding elements into this object and storing this object into List interface. Convert elements of ArrayList into an array by using toArray().
     
  18. Implementing a Queue
    In this section, you will learn how to implement the queue. A queue holds a collection of data or elements and follows the FIFO ( First In First Out) rule.
        
  19. Implementing a Stack
    In this section, you will learn how to implement a stack in Java. A Stack is like a bucket in which you can put elements one-by-one in sequence and retrieve elements from the bucket according to the sequence of the last entered element.
      
  20. Implementing a Least-Recently-Used (LRU) Cache
    In this section, you will learn about the least-recently- used(LRU) cache in Java. LRU Cache helps you how to use the buffer and how to limit or fixed the size of buffer and how to manage storing and retrieving process of the buffer which size is limited.
        
  21. Creating a Copy of a Collection
    In this section, you will learn how to create and then copy the collection. The copied collection contains the reference to the object. In-fact, objects are not cloned.
        
  22. Making a Collection Read-Only
    This section describes you how to make a collection read-only. In this section, list (component of the collection) has been represented for making it read-only. By default, list is not read-only.
         
  23. Sorting a List
    This section gives you the best illustration for sorting elements of a Collection. You can see how to sort all elements of a Collection in ascending or descending order.
        
  24. Creating a Hash Table
    This section explains the implementation of the hash table. What is the hash table and how to create that? Hash Table holds the records according to the unique key value. It stores the non-contiguous key for several values.
        
  25. Finding an Element in a Sorted Array
    In the sorted array, searching is very easy. In this section, you will learn how to sort an array and how to find a text in the sorted array. For binary search first you must sort the array and then apply the binary search.
        
  26. Reading a Properties File
    In this section, you will learn how to read the key-value of properties files in Java. The properties file provides the general text editor, which have the keys and it's values.
        
  27. Getting all properties of a properties file
    In this section, you will learn how to get all keys and it's values of the properties files in Java. Java provides the features to collection of all keys and values of the properties file.
        
  28. Setting property to a properties file
    In this section, you will learn how to add the keys and it's values of the properties files in Java. You know the properties files have the keys and values of the properties files.
        
  29. Scheduling a Timer Task to Run at a Certain Time and Repeatedly
    In this section, you can learn how to schedule a timer task to run at a certain time and repeatedly. There is an example given for the illustration. This program asks you for the way of performing the task whether at the certain time or repeatedly.
        
  30. Getting the Current Time
    In this section, through the given program you can get the current time in the proper format (Hour:Minute:Second AM/PM). This program shows the current time by using the various methods of the Calendar class.
        
  31. Getting Information of All Available Time Zones
    Time Zone is the specified part of the earth that holds the special standard of the time i.e. termed as local time. Usually time zone is based on the GMT (Greenwich Mean Time).
        
  32. Getting the Current Date
    In this section, through the given program you can get the current date in the proper format (Day/Month/Year). This program shows the current date by using the various methods and fields of the Calendar class.
        
  33. Determining the Number of Days in a Month
    This section will show the way of counting the number of days of a month in the specified year. Following program takes the year as input through the keyboard and shows the number of days in the February month of the mentioned year if the year is valid other it will show the error message and terminate the program.
        
  34. Comparing Dates
    This example illustrates you how to compare two dates. Generally dates are calculated in milliseconds. In this section, we will show you how to compare two given dates. To compare dates the given program is helpful for application development. You can easily use the code for comparing dates.
        
  35. Determining a Person's Age
    Here, you can calculate the age of a person easily through the given program.
     
  36. Determining If a Year Is a Leap Year
    Leap Year is the year contains an extra day. In the leap year, February month contains 29 days since normally February month has 28 days. The year which is completely divided by 4 that is the leap year.
        
  37. Determining the Day-of-Week for a Particular Date
    This section simply show the current day in word i.e. the Day of Week for a particular date. Here, you can learn about the way of doing that.
       
  38. What is a JAR file in Java
    JAR file is the compressed file format. You can store many files in a JAR file. JAR stands for the Java Archive. This file format is used to distribute a set of java classes. This file helps you to reduce the file size and collect many file in one by compressing files.
        
  39. Creating a JAR file in Java
    This section provides you to the creating a jar file through the java source code by using the jar tool command which is provided by the JDK (Java Development Kit).
        
  40. Listing the Entries of a JAR File Manifest
    This section shows you how you can read the content of jar file from your java program and list the content. This section helps you to view the contents of the jar file without extracting it.
        
  41. Listing the Main Attributes in a JAR File Manifest
    Jar Manifest file is the main section of a jar file. This file contains the detailed information about the specific individual jar file. It contains the complete information about the jar file, each and every section or particular information is separated by new line.
      
  42. Creating a ZIP File
    Zip file format is the popular method of data compression. Zip file contains many files in compressed format. You can say the files are stored in the zip format with compression. The file which is in the zip format holds the ".zip" extension.
        
  43. Listing the Contents of a ZIP File
    Section, provides the way for listing all the elements of a zip file through the java code. Following program helps you for the appropriate. You can directly copy and paste the code in your java application for showing list of elements present in the zip file format.
        
  44. Retrieving a Compressed File from a ZIP File
    How to unzip (extract) a zip file? How to retrieve elements from a zip format file? All these type of questions are solved through the following example.
        
  45. The Java Logging Program
    This section introduce you about Java logging and how to use the logger in Java program to log the error and messages into the log file. Explanation of java logging is explained in the given example program.
        
  46. Logging an Exception
    This section introduces you the concept of logging exception handling. When certain conditions are not followed or wrong then compiler shows a message which is mentioned under the specific exception.
        
  47. Preventing a Logger from Forwarding Log Records to Its Parent
    This section describes how to forward log records to its parent. You know that a logger sends both log records (messages declared before setting the log for it's parent and log messages after setting for it's parent) to handlers, parent or ancestor.
        
  48. Writing Log Records to a Log File
    This section demonstrates for writing log records to a log file. Logger provides different types of level like: warning, info and severe that have log records.
       
  49. Writing Log Records to Standard Error
    This section demonstrates how to write log records to standard error in Java. Java provides the facility for handling an error through the help of ConsoleHandler class.
     
  50. Writing Log Records Only After a Condition Occurs
    This section deals with log records those have been written in a log file if  the "if" conditions are certified otherwise not.
     
  51. Setting a Filter on a Logger Handler
    This section illustrates you how to set filter on a logger handler in Java. Generally, Filter is a program that provides the facility to get data if the certain conditions are satisfied otherwise don't get any data. In other words, you get data to be filtered.
      
  52. What is Logging Level
    Logger:
    Logger is the class of java.util.logging package that extends the Object class. Java provides logging APIs like: Logger, Level, Handler etc. for implementing logging features in your java application.
     
  53. Getting the Log Level of a Logger
    This section helps you to learn about the getting log level of a logger through the java program and illustrates how to get it. The Logger provides various types of levels of a logger like: INFO, WARNING, SEVERE and FINEST etc.
      
  54. Comparing Log Levels
    This section describes, how to compare log levels to each other. In Java, the Level class assigns a set of multiple logging levels that has already an individual integer type value.
     
  55. Creating a Custom Log Level
    This section tells you how to create a custom log level that means log levels are created by users for own need. Java logging class provides some levels like: INFO, WARNING, SEVERE, FINEST etc.
     
  56. Setting the Formatter of a Logger Handler
    This section discussed how to set the formatter of a logger handler. Java provides a logger handler that uses a formatter for writing log records for a log file that can be either xml file or other.
     
  57. Creating a Custom Formatter for a Logger Handler
    This section tells you how to create a custom formatter for a logger handler. Java provides two types formatter SimpleFormatter and XMLFormatter. But, the java logging package allows for creating a custom formatter through the logger handler.
      
  58. Limiting the Size of a Log File
    This section illustrates you how to limit the size of a log file in Java. Log files haven't any boundation at the file creation time but Java provides the facility for limiting the size of a log file with the help of FileHandler.
     
  59. Regular Expression Search Program
    Regular Expression is used to perform many string related operations. This is the way to manipulate different kind of operations like search, edit and manipulating string can be performed by the regular expression. It has both type characters (literal characters and meta characters).
        
  60. Applying Regular Expressions on the Contents of a File
    This section illustrates you how to search a string in a file content. Following takes the file name from which the given string/text has to be searched. File name must be text file (with ".txt" extension).
        
  61. Removing duplicate white space from a String
    In this section, you will learn how to remove all white spaces from the given string by using the regular expressions. This section gives you a example for the best illustration about the way of removing all the duplicate white spaces from the given string.
        
  62. Removing duplicate white space from a text file
    This section shows you how to remove all duplicate white spaces from a specific text file. In this section a program is given as follows for the best illustration for how to remove all duplicate white spaces from the given text file. This program reads the file line-by-line for search the duplicate white spaces and replace all duplicate white spaces with the single white space.
       
  63. Greedy and Nongreedy Matching in a Regular Expression
    This section illustrates you how to match a string in the given string through the Greedy and Non-Greedy way of matching. Here you can learn about the Greedy and Non-Greedy way of matching the word.
        
  64. Escaping Special Characters in a Pattern
    This section illustrates you how to escape all special characters from the given string or text. Here, you can learn the way of detecting all special characters present in the given string.
        
  65. Parsing Character-Separated Data with a Regular Expression
    This section illustrates you how to split String data ( separated by "," or "and/or"). These words are shown in a new line without the word or characters which is used for separation the word of the sentences through the given regular expression of the following program.
        
  66. Setting Case Sensitivity in a Regular Expression
    This section describes the method to set the patter is either case sensitive or not. Actually, by default the patter is in the case sensitive. Whenever it need to be set for the case insensitivity then you have to use the appropriate code followed in following program.
        
  67. Compiling a Pattern with Multiple Flags
    In this section you will learn how to compile a pattern with multiple flags like multiline, case insensitivity of the characters in the string etc. This section provides you an example for the implementation of the concept about how is it done?
      
  68. Capturing Text in a Group in a Regular Expression
    This section illustrates you how to capture the text in a group through the regular expression. Here, you can learn the procedure of capturing text made by the given alphabets (mentioned in the code of the program "a", "b" and "c") from the group of text.
     
  69. Getting the Indices of a Matching Group in a Regular Expression
    Here, in this section, you will find the lower and upper indices of the matching group of the text  through the regular expression in Java.
      
  70. Using the Captured Text of a Group within a Replacement Pattern
    In this section, you will learn how to use the captured text from the group of the text. This section illustrates you how to capture the string or text through the regular expression and it is also used through the regular expression.
     
  71. Reading Lines from a String Using a Regular Expression
    You will learn how to separate a string by detecting the line. An example has been given in the section for the best illustration of the procedure of reading of line from the file.
     
  72. Removing Line Termination Characters from a String
    This section provides you an example of with program code which reads the string or text of a text file which is mentioned by the user and replacing all the new line character by the double quote with one space (" ") wherever it found.
      
  73. Parsing a String into Paragraphs Using a Regular Expression
    This section tells you how to parse the string into the paragraphs using regular expression in Java. In this section, you will learn about the topic through the following program.
      
  74. Calculate process time in Java
    This section provides the facility to calculate the process time of the completion of the operation through the Java program. In this section, an example with the complete code of the program is given for the best illustration of the procedure of calculating the process time in which any type of operation is completed after whole processing.
     
  75. Decreasing process time by caching through the Hash Table in Java
    This section illustrates you how to improve the process time of any type of the operation performed by your java program. You can easily improve the process completion time of the operation by using more and more cache of your system.
     
  76. Simple Hash Table implementation in Java
    This section describes the complete Hash Table implementation from the basic in Java. In this section, you will see how to store some information and retrieve when it need to search for checking whether the given title exists or not. This section is very helpful for your java application for which the following program supports for working the software in very efficient manner.
      
  77. Hash Table for maintaining popup menus in Java
    This section shows the procedure of maintaining popup menus through hash table in your Java program. This section provides you an example with the complete code of the program that has been used to create and maintain popup menus in Java.
      
  78. Partial Search from Hash Table in Java
    This section illustrates you how to put some string in the Hash Table through the Java program and get these string easily. Here, you will see that the given string which is mentioned with the command "java <file name>" in the command line.
      
  79. Writing and reading from/to a serialized file through Hash Table in Java
    This section illustrates you how to read and write from/to a serialized file through the hash table in Java. This section provides an example with the complete code of the program.
      
  80. Thread Access through the Hash Table in Java
    Here, you will learn about how a thread is accessed by using the hash table in Java.
     
  81. Get previous, current and next date in Java
    In this section, you will learn how to get previous, current and next date in java. The java util package provides the facility of it. 
     
  82. Get first day of week
    In this section, we will learn how to get the first day of  week in Java. As we know that GregorianCalendar provides the current date, month and year in a yearly calendar. 
     
  83. Preferences Overview
    In this section you will learn about preferences and all the methods that modify preference data are allowed to operate a certain work. It allow to store the user and system configuration data .
      
  84. Multiple Value initialization and retrieval by put and get method
    In this example you are going to find out the flow of using put and get method of the preferences. After reading, coding, and running you are able to use the get and put method.
      
  85. Listening for Changes to Preference Values in a Preference Node

    In this section you will learn how to access the user's node and retrieve the stored information in the class.
      
  86. Export System Preferences
    In this section you will learn that how a user can access the System preferences. Here we are going to make it easier to understand the step be step process by the complete example on this topic.
      
  87. Exporting the User Type Preferences in a Subtree of Preference Node
    In this section you will learn that how a user can access the User preferences. Here we are going to make it easier to understand the step be step process by the complete example on this topic.
      
  88. Saving and Retrieving a Preference Value
    In this section you will learn about the way to retrieves the user preference node using the same class and saves and retrieves a preference in the node. Here an example is also provided for learning about the topic in detailed form.  
      
  89. Change the value of Preferences by user
    In the given example we explain a simple way for using the get() and put() method in preferences. In preferences the get() is the most useful method with the help of which you can stored data in the class and can change by put() method.
      
  90. Using get() method in preferences
    Get is the most useful method with the help of which you can stored data in the class and can also print the value of that stored value by using simple print command.
      
  91. Using put() method in preferences
     
    By this example you will learn that how a put function is used in the program.
      
  92. Create Frame with Preferences
    In this section you will learn how to use the preferences in frame. The example will make it easier to understand to use the preferences with frame window.
     
  93. Clone method example in Java
    In this section, you will learn how to use clone() method of Cloneable interface in java. The clone is a method in java for handling the object duplication. This is the method of Cloneable interface (java.lang package). 
      
  94. SortedMap (interface) example in java Collection Framework
    A SortedMap is a map that maintains its entries in ascending order, sorted according to the keys' natural order, or according to a Comparator provided at SortedMap creation time.
          
  95. Determining If a Preference Node Contains a Specific Key
    This section demonstrates you to determine whether the Preference Node contains a  Specific key or not. You can see in the given example that we have create a method contain(String key) of Boolean type.
      
  96. Determining If a Preference Node Contains a Specific Value
    This section demonstrates you to determine whether the Preference code contains the specified value or not by enumerating the key/value pairs in a preference node and checks each value for a match.
      
  97. Removing a Preference from a Preference Node
    This section demonstrates you to remove the preference from a preference node. You can see in the given example that in order to remove the preference from the Preference node 'Roseindia'.
     
  98. Getting and Setting Java Type Values in a Preference
    As you know that a preference node holds only string values. Therefore the Preferences class provides some convenient methods to convert the Java types into string.
      
  99. Getting the Maximum Size of a Preference Key and Value
    This section demonstrates you to get the maximum size of Preference key and value. You can see in the given example that we have used the fields of class Preferences.
       
  100. Creating a Preference Node
    This section demonstrates you to create a Preference Node in C. As you know that there are two types of Preference nodes, User Preference Node and System Preference Node.
      
  101. Removing a Preference Node
    This section demonstrates you to remove the Preference node. You can see in the given example that firstly you have to get the specified node using the method userRoot().node("/Roseindia Employees") method.
     
  102. Determining If a Preference Node Exists
    A preference node can be created automatically by using the methods Preferences.node(), Preferences.userNodeForPackage(), or Preferences.systemNodeForPackage().
     
  103. Retrieving the Parent and Child Nodes of a Preference Node
    In this section, we are going to retrieve the Parent and Child nodes of a Preference Node. You can see in the given example that we have used Preferences.userNodeForPackage(java.lang.String.class) to get the Preference node.
     
  104. Finding a Preference in a Preference Tree
    You can see in the given example that we are retrieving the keys and values of the Preference node 'Java Types'. For this, we have create a method find(Preferences p) and use different methods inside it.
     
  105. Importing Preferences
    Preferences can be exported using the methods Preferences.exportNode() and Preferences.exportSubtree(). This exported data can be imported by using the method Preferences.importPreferences().
       
  106. Listening for Changes to Preference Values in a Preference Node
    This section demonstrates you to change the Preference values in a Preference node. You can see in the given example, we have used the class PreferenceChangeEvent which occurs when a preference is added.
      
  107. Determining When a Preference Node Is Added or Removed
    This section illustrates you to determine when a Preference Node is added or removed. You can see in the given example that we have add a new node by using the method userRoot().node("/Hello World").
      
  108. Implementing a Simple Event Notifier
    The Observer and Observable classes are useful for implementing a simple event notifier. The Observer class informed the changes that occurred in observable objects and Observable class represents an object that the application wants to have observed.
      
  109. Properties file in Java
    In this section, you will know about the properties file. The properties file is a simple text file. Properties file contains keys and values for the specific key.

     
  110. Random alpha numeric string of fixed size

  111. Java current Date
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 22, 2008

Related Tutorials

Discuss: Java Util Examples List  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
sooraj kumar
August 31, 2011
java all question anwer list send please

java is like .i m intresting in java.
sharan
September 27, 2012
Java

Explain hoe to assign properties to thread with example?
DMCA.com