Skip to content

Commit 49c4ee2

Browse files
committed
Updated blogpost example
1 parent 7d76ced commit 49c4ee2

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

collections/linkedlist/get-an-index-of-element-of-linkedlist/LinkedListIndexOf.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@ public static void main(String[] args) {
2626
System.out.println(linkedList);
2727

2828
// get first index of GoldSpot
29-
int index = linkedList.indexOf("GoldSpot"); // 2
29+
int index = linkedList.indexOf("DrPepper"); // 1
3030

31-
System.out.println("\nIndex of the GoldSpot in linkedList is: "+ index);
31+
System.out.println("\nIndex of the DrPepper in linkedList is: "+ index);
32+
33+
// get first index of GoldSpot
34+
int indexGS = linkedList.indexOf("GoldSpot"); // 2
35+
36+
System.out.println("\nIndex of the GoldSpot in linkedList is: "+ indexGS);
3237

3338
// get first index of Moxie
3439
int indexMoxie = linkedList.indexOf("Moxie"); // 5

collections/linkedlist/get-an-index-of-element-of-linkedlist/LinkedListLastIndexOf.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,18 @@ public static void main(String[] args) {
2626
System.out.println(linkedList);
2727

2828
// get last index of GoldSpot
29-
int index = linkedList.lastIndexOf("GoldSpot"); // 6
29+
int index = linkedList.lastIndexOf("DrPepper"); // 1
3030

31-
System.out.println("\nIndex of the GoldSpot in linkedList is: "+ index);
31+
System.out.println("\nLast index of the DrPepper in linkedList is: "+ index);
32+
33+
// get last index of GoldSpot
34+
int indexGS = linkedList.lastIndexOf("GoldSpot"); // 6
35+
36+
System.out.println("\nLast index of the GoldSpot in linkedList is: "+ indexGS);
3237

3338
// get last index of Moxie
3439
int indexMoxie = linkedList.lastIndexOf("Moxie"); // 7
3540

36-
System.out.println("\nIndex of the Moxie in linkedList is: "+ indexMoxie);
41+
System.out.println("\nLast index of the Moxie in linkedList is: "+ indexMoxie);
3742
}
3843
}

0 commit comments

Comments
 (0)