Share a useful Java code that returns a comma-separated number to be sorted from a large to a small way

Source: Internet
Author: User

Original: Share a very useful Java code, you can sort the comma-separated numbers in a large-to-small way to return

Source code: Http://www.zuidaima.com/share/1550463693032448.htm

For web development, the sorting of multiple IDs is very practical and there is a need for cattle people to download.

Package Com.zuidaima.math;import java.util.arrays;/*** @author Www.zuidaima.com**/public class Sortidstring {public static void Main (string[] args) {String user_ids = "1,3,2,299,33,2"; string[] _ids = User_ids.split (","); System.out.println ("before sort:" + arrays.tostring (_ids). ReplaceAll ("\\[|\\]", "")); for (int i = 0; i < _ids.length; i++) {int largest = i;for (int j = i; J < _ids.length; J + +) {if (Integer.parseint (_ids[j]) > Integer.parseint (_ids[l Argest]) largest = j;} int temp;temp = Integer.parseint (_ids[i]); _ids[i] = _ids[largest];_ids[largest] = temp + "";} System.out.println ("After sorting:" + arrays.tostring (_ids). ReplaceAll ("\\[|\\]", ""));}}


Share a useful Java code that returns a comma-separated number to be sorted from a large to a small way

Related Article

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.