Manipulate the Java array

xiaoxiao2021-03-06  86

If you have done a lot of Java programs, you may be familiar with the Java collection class, such as Vector and ArrayList. You can create a collection and increasing the element in it: list lst = new arraylist (); lst.add (new integer (37)); in this special example, a integer value 37 is used to construct an Integer package class object , Then that object is added to the list. This simple example shows a basis for the collection - they are used to manipulate a column of objects, each of which is a class or interface type. Therefore, an ArrayList can contain objects of Object, String, Float, and Runnable types. The set class cannot be used for the list of raw data types, such as integer arrays. If you use the original type of original type in your program, how do you manipulate them? This trick gives you a few techniques you can use. The first technology is sorted. The Java.util.Arays class contains a class method for sorting and looking for arrays, such as Import Java.util.Arrays; Public Class ArrayDemo1 {Public Static Void Main (String Args []) {Int Vec [] = {37, 47 , 23, -5, 19, 56}; arrays.sort (vec); for (int i = 0; i 转载请注明原文地址:https://www.9cbs.com/read-120964.html


New Post(0)