https://github.com/msarmadqadeer/java-tasks
These are all java tasks that I created during studying programming fundamentals subject.
https://github.com/msarmadqadeer/java-tasks
java java-tasks programming-fundamentals semester-2
Last synced: 4 months ago
JSON representation
These are all java tasks that I created during studying programming fundamentals subject.
- Host: GitHub
- URL: https://github.com/msarmadqadeer/java-tasks
- Owner: MSarmadQadeer
- Created: 2022-01-30T09:41:28.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-30T10:39:42.000Z (over 3 years ago)
- Last Synced: 2025-01-19T14:28:23.474Z (5 months ago)
- Topics: java, java-tasks, programming-fundamentals, semester-2
- Language: Java
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# java-tasks
These are all java tasks that I created during studying programming fundamentals subject.
## fun fact :joy:
In the above Java files, there is a file _`SarmadiList.java`_.
### story behind _`SarmadiList.java`_
When we studied **Arrays in Java**, we came to know that in Java the **length of Arrays is immutable (fixed)**. And we cannot append any item to Arrays in Java as we do in Lists in Python.
At that time I created a method in Java that takes two arguments and returns a new array.
1. **1st Argument** is an Array in which I want to insert another entry.
2. **2nd Argument** is a Number that I want to insert at the end.```java
public static int[] append(int[] list, int value) {
int[] newList = new int[list.length + 1];
for (int i = 0; i < list.length; i++) {
newList[i] = list[i];
}
newList[newList.length - 1] = value;
return newList;
}
```What it does is that it creates a new Array with the length of 1+ in the length of the previous Array. After that, it inserts all the values of a previous Array into the new Array, and the number that it takes as a 2nd argument is inserted at the last index of the new Array. Finally, it returns the new Array.
After doing this, I felt like I conquered something :rofl:.
### what I learned :sparkles:
When I show this to my teacher, he told me that by doing this I am creating a new Array in memory and not appending it at the end of that previous Array, which is not memory efficient.