Skip to content

Instantly share code, notes, and snippets.

String arr[][] = new String[3][];
arr[0] = new String[3];//3 columns
arr[1] = new String[2];//2 columns
arr[2] = new String[5];//5 columns
for (int i = 0; i < arr.length; i = i+1){
//each row has a diff column
for (int j = 0; j < arr[i].length ; j = j+1){ //NOTICE: arr[i].length
arr[i][j] = i + "" + j + " ";
System.out.print(arr[i][j]);
// Declaring a Rectangular Matrix
String arr[][] = new String[6][7];
int row = arr.length;// Row = 6
int col = arr[0].length; // Columns = 7
//Printing the Matrix using FOR Loop
for (int i = 0; i < row; i = i + 1) {
for (int j = 0; j < col; j = j + 1) {
arr[i][j] = i + "" + j + " ";
System.out.print(arr[i][j]);
/* Change all nodes to 42 */
ListNode runner = list;
//Change values as itrarte
while (runner != null){
runner.data = 42;
runner = runner.next;
}
/* Add nodes with 42 in the end */
public void addNodeEnd{
ListNode runner = list;
while(runner.next != null){
runner = runner.next;
}
runner.next = new ListNode(42, null);
}
public void set(int index, int value){
ListNode runner = front;
while(index != 0){
runner = runner.next;
index--;
}
runner.data = value;
}
public int min(){
if (front == null)
throw new NoSuchElementException();
int min = 2147483647;// Max int value
ListNode runner = front;
while (runner != null){
if (runner.data < min){
min = runner.data;
}
public int lastIndexOf(int num){
if (front == null)
return -1;
int index = 0;
int lastIndex = -1;
ListNode runner = front;
while (runner != null){
if (runner.data == num){
public int countDuplicates(){
if (front == null || front.next == null)
return 0;
int duplicateCount = 0;
int temp = front.data;
ListNode runner = front.next;
while (runner != null){
if (temp == runner.data){
public int deleteBack(){
if (front == null)
throw new NoSuchElementException();
// Only one node is present
if (front.next == null){
int deletedData = front.data;
front = null;
return deletedData;
}
// Traditional Iteration for LinkedList
LinkedList runner = head;
while(runner != head){
System.out.println(runner.data);
runner = runner.next;
}
// The for loop
for (LinkedList runner = head; runner != null; runner = runner.next{
System.out.println(runner.data);