Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to get elements by index java

ArrayList<String> list = //List instance
 
String firstElement = list.get(0);         
String sixthElement = list.get(5);       
Comment

get index of element java

// if you're too lazy to do anything fancy
// here's a code snippet for ya

// replace 'TYPE' with whatever type your using
// like 'int' or 'String' for example
public static int indexOf(TYPE[] arr, TYPE element)
{
	for (int index = 0; index < arr.length; index++)
    {
    	if (arr[index] == element)
          	return index;
      	else break;
    }
  	
  	// the '-1' is the unique value to
  	// inform you that no element was found
  	return -1;
}
Comment

get index of element in array java

System.out.println(new String(list).indexOf("e")); 
Comment

java array get index

 public int getArrayIndex(int[] arr,int value) {

        int k=0;
        for(int i=0;i<arr.length;i++){

            if(arr[i]==value){
                k=i;
                break;
            }
        }
    return k;
}
Comment

PREVIOUS NEXT
Code Example
Java :: list of string to string array in java 
Java :: java convert pdf to image 
Java :: vscode code formatter cannot format 
Java :: thread java timer 
Java :: File Appender log4j2.properties spring 
Java :: declare a hashmap in java 
Java :: reversing the linked list 
Java :: if else statement 
Java :: print symbol in pyramid shape in java 
Java :: java cannot find file path 
Java :: type of exception in java 
Java :: add two variables in Java 
Java :: Java The Throw/Throws Keyword 
Java :: print all numbers from 1 to n java 
Java :: java map keyset to list 
Java :: set text in edittext android 
Java :: setter getter array java 
Java :: cant change button color when app run android studio 
Java :: kruskal java 
Java :: thread implements runnable 
Java :: android get device hieght 
Java :: jsp initialization 
Java :: java print 2d array row and column 
Java :: org.apache.hadoop.mapred.JobClient.runJob(JobClient.java:876) 
Java :: java code for scientific calculator GUI 
Java :: implements java 
Java :: add close button on right top corner of alert dialog box for android 
Java :: how to generate random large string in java 
Java :: java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider 
Java :: could not load main class java 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =