summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbdus <abdus@abdus.net>2021-05-03 14:20:07 +0530
committerAbdus <abdus@abdus.net>2021-05-03 14:20:07 +0530
commit9a8ccf24048f0718b7df39d2548fa6e9fa6efa40 (patch)
treef7122e3c435ee743b15215dc7b821501a9db49f6
parent4ca3bc3d0607c7c50d14d7b3f03cfa6ba55b0856 (diff)
downloadabdus.net-9a8ccf24048f0718b7df39d2548fa6e9fa6efa40.tar.bz2
abdus.net-9a8ccf24048f0718b7df39d2548fa6e9fa6efa40.zip
new notes
-rw-r--r--.vim-session.vim10
-rw-r--r--content/notes/java-basics.md100
2 files changed, 106 insertions, 4 deletions
diff --git a/.vim-session.vim b/.vim-session.vim
index a434944..4065e50 100644
--- a/.vim-session.vim
+++ b/.vim-session.vim
@@ -7,7 +7,7 @@ if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
let s:wipebuf = bufnr('%')
endif
set shortmess=aoO
-badd +219 content/notes/java-basics.md
+badd +295 content/notes/java-basics.md
argglobal
%argdel
$argadd content/posts/typescript-webpack-setup.md
@@ -33,12 +33,14 @@ normal! zo
normal! zo
253
normal! zo
-let s:l = 288 - ((2 * winheight(0) + 24) / 48)
+307
+normal! zo
+let s:l = 388 - ((27 * winheight(0) + 24) / 48)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
-288
-normal! 0
+388
+normal! 031|
tabnext 1
if exists('s:wipebuf') && getbufvar(s:wipebuf, '&buftype') isnot# 'terminal'
silent exe 'bwipe ' . s:wipebuf
diff --git a/content/notes/java-basics.md b/content/notes/java-basics.md
index 8c23692..86b98a7 100644
--- a/content/notes/java-basics.md
+++ b/content/notes/java-basics.md
@@ -286,3 +286,103 @@ Some classes that provides more flexible ways to work with string:
- `String toLowerCase()`: converts to lower case
- `String toUpperCase()`: converts to upper case
- `String replace(char old, char new)`: replaces char with a new one
+
+## Array
+
+```java
+class Arr {
+ public static void main(String args[]) {
+ int myArr[] = new int[20]; // array of int of length 20
+ }
+}
+```
+
+### Jagged Array
+
+a jagged array is an array of arrays such that member arrays
+can be of different sizes.
+
+```java
+class Jagged {
+ public static void main(String args[]) {
+ int arr[][] = new int[3][];
+ arr[0] = new int[10];
+ arr[1] = new int[12];
+ arr[2] = new int[15];
+ }
+}
+```
+
+### Clone an Array
+
+there are multiple methods for cloning an array.
+
+#### Shallow Clone
+
+does not clone, just set the memory location
+
+```java
+int[] arr = new int[10];
+int copy[] = new int[arr.length];
+
+copy = arr;
+```
+
+#### Iterate and Copy
+
+```java
+int[] arr = new int[10];
+int copy[] = new int[arr.length];
+
+for (int i = 0; i < arr.length; i++) {
+ copy[i] = arr[i];
+}
+```
+
+#### using Clone()
+
+```java
+int[] arr = new int[10];
+int[] copy = arr.clone();
+```
+
+#### using Arrays.copyOf()
+
+```java
+import java.util.Arrays;
+
+int[] arr = {1, 2, 3, 5, 10};
+int[] copy = Arrays.copyOf(arr, 5); // copy first 5 element
+```
+
+#### using Arrays.copyOfRange()
+
+```java
+import java.util.Arrays;
+
+int[] arr = {1, 2, 3, 5, 10};
+int[] copy = Arrays.copyOfRange(arr, 2, 4); // 2 is index, and 4 is the length
+```
+
+### Array to String
+
+an array can be converted to string using Arrays.toString() or
+StringBuilder.append()
+
+```java
+import java.util.Arrays;
+
+int[] arr = {1, 2, 3, 5, 10};
+System.out.println(Arrays.toString(arr));
+
+StringBuilder str = new StringBuilder("Hello");
+char[] world = { ' ', 'W', 'o', 'r', 'l', 'd' };
+
+str.append(world);
+```
+
+### Array equality
+
+to check whether two arrays are equal, Arrays.equals() method can be used:
+`Arrays.equals(arr1, arr2);`. Similarly for nested arrays, use
+`Arrays.deepEquals(arr1, arr2);`