Java Learning notes: arrays

Source: Internet
Author: User

package myjava;/** *  Arrays  *  @author  Administrator * */import  java.util.*;p Ublic class myarray {public static void main (String args[])  {//  Array Sorting int array[] = { 1, 9, 4, 2, 8, 6, 7  }; Arrays.sort (array);//  array output for  (Int item : array)  {system.out.println (item);}   Array to string string str = arrays.tostring (array); System.out.println (str);//  gets the array length System.out.println ("Array length:"  + array.length);int[][]  newarray = new int[2][5]; System.out.println ("second-dimensional array length: "  + newarray[0].length);//  array inversion arraylist arraylist  = new arraylist (), Arraylist.add ("a"), Arraylist.add ("B"), Arraylist.add ("C"); Collections.reverse (arrayList); System.out.println ("reverse sort: "  + arraylist);//  array Maximum minimum value integer[] numners = {  8, 3, 6, 1, 4, 7 };int min =  (int)  collections.min (Arrays.asList (numners)); int  max =  (int)  collections.max (arrays.aslist (numners)); SYSTEM.OUT.PRINTLN ("Minimum value is: "  + min); SYSTEM.OUT.PRINTLN ("Maximum value is: "  + max);//  array merge string a[] = {  "a",  "B" ,  "C"  }; string b[] = {  "D",  "E"  }; List list = new arraylist (Arrays.aslist (a)); List.addall (Arrays.aslist (b)); Object[] c  = list.toarray (); SYSTEM.OUT.PRINTLN ("Array C is:"  + arrays.tostring (c));//  array padding int array2[] = new  INT[6]; Arrays.fill (array2, 100); System.out.println ("populated array:"  + arrays.tostring (array2));//  Array expansion string[] names =  new String[] {  "A",  "B",  "C"  }; string[] extended = new string[5];extended[3] =  "D";extended[4] =  "E"; System.arraycopy (NAMes, 0, extended, 0, names.length);for  (string row : extended)  { System.out.println (row);}   Delete array element arraylist arraylist2 = new arraylist (); Arraylist2.clear (); Arraylist2.add (0,   " 0  elements"), Arraylist2.add (1,  " 1  elements"), Arraylist2.add (2,  "the first  2  Elements "); Arraylist2.remove (1); System.out.println ("After array delete element:" +arraylist2);}}


Java Learning notes: arrays

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.