Search for collections elements, get month with DateFormatSymbols

Source: Internet
Author: User
Tags month name

Import Java.util.collections;import Java.util.list;import java.text.dateformatsymbols;import Java.util.LinkedList; Public classsearchcollections { Public Static voidMain (string[] args) {List List=NewLinkedList (); /** * DateFormatSymbols is a public class used to encapsulate localizable date-time formatted data, such as month name, day of the week, and time zone data. DateFormat and SimpleDateFormat * Both use DateFormatSymbols to encapsulate this information.         Sysmbols: Symbol, Tag * Constructs a DateFormatSymbols object by loading the format data from the default locale resource. */DateFormatSymbols DFS=NewDateFormatSymbols (); string[] months= Dfs.getmonths ();//Get the Month         for(inti =0; i < months.length; i++) {String month=Months[i];        List.add (month); } collections.sort (list);//if it is not sorted here, the order is right, and the following results appear after sort!System. out. println ("name of month:"+list); /** * Month Name: [, January, July, March, September, February, May, August, June, November, December, October, April] * Find its location in: 10 * month = December */                intindex = Collections.binarysearch (list,"December");//Find the list ' December ' in a binary way        if(index>0) {System. out. println ("find its location in:"+index); String Month= (String) list.Get(index);//List.get () method: Returns the element at the specified position in the list. System. out. println ("month ="+month); }    }}

Search for collections elements, get month with DateFormatSymbols

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.