How to add elements to an array by creating a method in java. The array is full
Reference example:
public class shuzucharu1 {
public static void main(String args[]){
int[] P={1,2,2,47,568,86};
int[] SB=new int[P.length 1];//The array length of SB is 7
int SB1=9;
SB[SB.length-1]=SB1;//When the following table in the SB array is 6, the value is 9
for(int i=0;i
SB[i]=P[i];
System.out.println(SB[i]);
}
System.out.println(SB[SB.length-1]);
}
}//First use the copy algorithm to copy the 6 numbers in the P array to SB. Because the length of the SB array is 7, the seventh number is the subscript 6, and it can be output directly outside the loop.
Insert an element into the sorted array
What type of numbers are in your array? Give an example of int type
import java.util.Arrays;
public class ArySort {
public static void main(String[] args) {
int[] ary = {1, 3, 5,7,9,11};
int[] ary2 = new int[ary.length 1];
System.arraycopy(ary, 0, ary2, 0, ary.length);
ary2[ary.length] = 6;
Arrays.sort(ary2);
for(int value: ary2){
System.out.print(value " ");
}
}
}
--------------
1 3 5 6 7 9 11
How to add an element to the head and tail of the data group in Java
java ArrayList uses add to insert an element. The example is as follows:
import java.util.ArrayList;
public class Test {
public static void main(String[] args) {
ArrayList list = new ArrayList();
list.add(0); //Insert the first element
list.add(1);
list.add(2);
list.add(3);
list.add(4);
list.add(5);
System.out.println(list); //Print list array
list.add(2, 7);
System.out.println(list);
}
}
The above is the detailed content of Methods to implement dynamic expansion of arrays in Java. For more information, please follow other related articles on the PHP Chinese website!

If you want to buy a top printer & scanner, this post lists some best printers and scanners and copiers including some top HP printers and scanners. php.cn Software not only provides useful computer software but also provides various computer tut

You can use the built-in Network Adapter troubleshooter in Windows 11 to find and fix problems with wireless and other network adapters. This post teaches you how to find and run Windows 11 network adapter troubleshooter with detailed instructions. S
![[Solved] Battlefield 2042 Black Screen Issues (7 Solutions) - MiniTool](https://img.php.cn/upload/article/001/242/473/174698221230413.png?x-oss-process=image/resize,p_40)
Battlefield 2042 black screen then crash is an annoying problem when gaming. How to fix it? This guide on php.cn Website aims at tackling this issue. Look it through carefully and we sincerely hope that our solutions will work fine for you.

Have you ever encountered Dev Error 11557 in Call of Duty: Modern Warfare 2 or Warzone 2? If you are, you come to the right place. In this post, php.cn provides some potential solutions to help you fix this error.

If you want to cancel your Apple Music subscription, there are several ways to do so. This post from php.cn tells you how to cancel your subscription using your iPhone, iPad, Android device, Mac, or the Apple TV.

Microsoft 365 offers several subscription plans for you to choose from. This post introduces and compares all Microsoft 365 plans. You can choose a preferred Microsoft 365 plan based on your own needs. To recover deleted or lost files like Office fil

The VLC media player is a free and open-source, portable, cross-platform media player software and streaming media server, which is available for desktop operating systems and mobile platforms. But some people find the “VLC not playing videos” issue

To manage your daily tasks, you can use the free task management app - Microsoft To Do. This post teaches you how to download Microsoft To Do on Windows 10/11, Mac, iPhone/iPad, or Android. If you are looking for more computer tips and solutions, you


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1
Easy-to-use and free code editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
