
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Join Function in Java
The join() method of Ints class returns a string containing the supplied int values separated by separator. The syntax is as follows −
public static String join(String separator, int[] arr)
Here, separator parameter is something that should appear between consecutive values, whereas arr is an array of int values.
Let us first see an example −
Example
import com.google.common.primitives.Ints; class Demo { public static void main(String[] args) { int[] myArr = { 10, 20, 30, 40, 50, 60,70, 80, 90, 100 }; System.out.println(Ints.join("-", myArr)); int index = Ints.indexOf(myArr, 40); if (index != -1) { System.out.println("Element 40 is in the array at position " + (index+1)); } else { System.out.println("Element 40 is not in the array"); } } }
Output
10-20-30-40-50-60-70-80-90-100 Element 40 is in the array at position 4
Advertisements