xxxxxxxxxx
import java.io.*;
import java.util.*;
class GFG {
public static void main(String[] args)
{
// Let us create different types of arrays and
// print their contents using Arrays.toString()
boolean[] boolArr = new boolean[] { true, true, false, true };
byte[] byteArr = new byte[] { 10, 20, 30 };
char[] charArr = new char[] { 'g', 'e', 'e', 'k', 's' };
double[] dblArr = new double[] { 1, 2, 3, 4 };
float[] floatArr = new float[] { 1, 2, 3, 4 };
int[] intArr = new int[] { 1, 2, 3, 4 };
long[] lomgArr = new long[] { 1, 2, 3, 4 };
Object[] objArr = new Object[] { 1, 2, 3, 4 };
short[] shortArr = new short[] { 1, 2, 3, 4 };
System.out.println(Arrays.toString(boolArr));
System.out.println(Arrays.toString(byteArr));
System.out.println(Arrays.toString(charArr));
System.out.println(Arrays.toString(dblArr));
System.out.println(Arrays.toString(floatArr));
System.out.println(Arrays.toString(intArr));
System.out.println(Arrays.toString(lomgArr));
System.out.println(Arrays.toString(objArr));
System.out.println(Arrays.toString(shortArr));
}
}
xxxxxxxxxx
int[] numbers = new int[10];
int[] names = new String[]{"John", "Jack"};
int length = names.length;
for (String name: names) {
System.out.println(name);
}
xxxxxxxxxx
Input: nums = [-4,-1,0,3,10]
Output: [0,1,9,16,100]
Explanation: After squaring, the array becomes [16,1,0,9,100].
After sorting, it becomes [0,1,9,16,100].
xxxxxxxxxx
// this is an array
var days = ["sunday","mondey","tuesday","wednesday"]
//here you can call arrays items using index number inside squar bracket
console.log(day[0])
console.log(day[1])
console.log(day[2])
xxxxxxxxxx
<!DOCTYPE html>
<html>
<body>
<script>
var str = ["1818-15-3", "1819-16-3"];
var arr = str.split(":");
document.write(arr[1] + ":" + arr[2]);
</script>
</body>
</html>
xxxxxxxxxx
const collection = {
length: 0,
addElements: function(elements) {
// obj.length will be incremented automatically
// every time an element is added.
// Returning what push returns; that is
// the new value of length property.
return [].push.call(this, elements);
},
removeElement: function() {
// obj.length will be decremented automatically
// every time an element is removed.
// Returning what pop returns; that is
// the removed element.
return [].pop.call(this);
}
}
collection.addElements(10, 20, 30);
console.log(collection.length); // 3
collection.removeElement();
console.log(collection.length); // 2