Data operation-related function notes

Source: Internet
Author: User
Tags arrays
Data operation-related function notes
1. Array replication function
System. arraycopy ()
System. arraycopy (source array, 0, target array, 0, copy length)
Example:
Public class TestArrCopy
{
Public static void main (String [] args)
{
Int ia [] = new int [] {1, 2, 3, 4, 5 };
Int ib [] = new int [] {9, 8, 7, 6, 5, 4, 3, 2 };
System. arraycopy (ia, 0, ib, 0, 3 );
// Copy the three elements starting from the subscript 0 in the source array ia to the array ib and store them from the subscript 0.
For (int I = 0; I <ia. length; I ++)
System. out. print (ia [I]);
For (int j = 0; j <ib. length; j ++)
System. out. print (ib [j]);
}
}
Result: 1234512365432
2. Array sorting function
Arrays. sort (array name)
Example program:
Import java. util .*;
Class Arrsort
{
Public static void main (String [] args)
{
Int ia [] = new int [] {2, 9, 3, 6, 7, 4 };
Arrays. sort (ia );
For (int I = 0; I <ia. length; I ++) System. out. print (ia [I]);
}
}
Result: 234679
3. Array comparison function (not element comparison)
Arrays. equals (array 1, array 2)
Example program:
Import java. util .*;
Class equ
{
Public static void main (String [] args)
{
Int ia [] = new int [] {1, 2 };
Int ib [] = new int [] {1, 2 };
If (Arrays. equals (ia, ib ))
System. out. println ("ia [] equals ib []");
Else
System. out. println ("ia [] not equals ib []");
}
}
Result: ia [] equals ib []

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.