-
-
Save DavidInnocent/e1952f1fd275f2966e08d7227bd628e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
public class start { | |
public static void main(String args[]) //static method | |
{ | |
String[] data = {"1", "2", "3", "4", "5", "2"}; | |
transformList(data); | |
} | |
public static void transformList(String listOfStrings[]) { | |
HashMap<String, Integer> maps = new HashMap<>(); | |
for (int x = 0; x < listOfStrings.length; x++) { | |
if (!maps.containsKey(listOfStrings[x])) { | |
maps.put(listOfStrings[x], x); | |
return; | |
} | |
System.out.println("We have the key hence there is a loop"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment