Skip to content

Instantly share code, notes, and snippets.

@DavidInnocent
Created June 13, 2022 12:13
Show Gist options
  • Save DavidInnocent/e1952f1fd275f2966e08d7227bd628e7 to your computer and use it in GitHub Desktop.
Save DavidInnocent/e1952f1fd275f2966e08d7227bd628e7 to your computer and use it in GitHub Desktop.
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