- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 34494 Articles for Programming
![Ankitha Reddy](https://www.tutorialspoint.com/assets/profiles/13550/profile/60_73963-1512711511.jpg)
156 Views
"On a mean, a developer spends a considerable quantity of your time doing mundane tasks compiling the code, packaging the binaries, deploying the binaries to the checkserver, testing the changes," copying the code from one location to another. To automate and simplify these tasks we can use build tools like Ant, Maven, Gradle etc.
![Arushi](https://www.tutorialspoint.com/assets/profiles/13510/profile/60_55588-1512537391.jpg)
2K+ Views
To count the number of lines in a fileInstantiate the FileInputStream class by passing an object of the required file as parameter to its constructor.Read the contents of the file to a bytearray using the read() method of FileInputStream class.Instantiate a String class by passing the byte array obtained, as a parameter its constructor.Now, split the above string into an array of strings using the split() method by passing the regular expression of the new line as a parameter to this method.Now, find the length of the obtained array.Exampleimport java.io.File; import java.io.FileInputStream; public class NumberOfCharacters { public static void main(String args[]) throws Exception{ ... Read More
![Paul Richard](https://www.tutorialspoint.com/assets/profiles/13505/profile/60_52698-1512536733.jpg)
5K+ Views
Read the number of words in text fileCreate a FileInputStream object by passing the required file (object) as a parameter to its constructor.Read the contents of the file using the read() method into a byte array. Insatiate a String class by passing the byte array to its constructor.Using split() method read the words of the String to an array.Create an integer variable, initialize it with 0, int the for loop for each element of the string array increment the count.Exampleimport java.io.File; import java.io.FileInputStream; public class Sample { public static void main(String args[]) throws Exception{ int count =0; File ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
12K+ Views
To convert the contents of an ArrayList to a String, create a StringBuffer object append the contents of the ArrayList to it, finally convert the StringBuffer object to String using the toString() method. Example import java.util.ArrayList; public class String_ArrayList { public static void main(String args[]) { ArrayList al = new ArrayList(); al.add("Hello"); al.add("are"); al.add("you"); StringBuffer sb = new StringBuffer(); for (String s : al) { sb.append(s); sb.append(" "); } String str = sb.toString(); System.out.println(str); } } Output Hello are you
![Arushi](https://www.tutorialspoint.com/assets/profiles/13510/profile/60_55588-1512537391.jpg)
315 Views
You can convert an array of Strings to a single array using the collect() method.ExampleLive Demoimport java.util.Arrays; import java.util.stream.Collectors; public class CreatngStringFromArray { public static void main(String args[]) { String [] myArray = {"Welcome", "to", "Tutorialspoint"}; String str = Arrays.stream(myArray).collect(Collectors.joining(" ")); System.out.println(str); } }OutputWelcome to Tutorialspoint
![Paul Richard](https://www.tutorialspoint.com/assets/profiles/13505/profile/60_52698-1512536733.jpg)
9K+ Views
You can extract a substring from a String using the substring() method of the String class to this method you need to pass the start and end indexes of the required substring.ExampleLive Demopublic class Substring { public static void main(String args[]) { String str = "Welcome to Tutorialspoint"; String sub = str.substring(10, 25); System.out.println(sub); } }OutputTutorialspoint
![Vikyath Ram](https://www.tutorialspoint.com/assets/profiles/13780/profile/60_74413-1512648006.jpg)
10K+ Views
To extract last n characters, simply print (length-n)th character to nth character using the charAt() method.ExampleLive Demopublic class ExtractingCharactersFromStrings { public static void main(String args[]) { String str = "Hi welcome to tutorialspoint"; int n = 5; int initial = str.length()-5; for(int i=initial; i
![Rishi Raj](https://www.tutorialspoint.com/assets/profiles/13777/profile/60_73169-1512647303.jpg)
622 Views
To find the consonants in the given String compare every character in it using the charAt() method with the vowel letters and remaining are consonants.ExampleLive Demopublic class FindingConsonants { public static void main(String args[]) { String str = new String("Hi Welcome to Tutorialspoint"); for(int i=0; i
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
2K+ Views
One way to find the vowels in a given String is to compare every character in it using the charAt() method with the vowel letters. Example Live Demo public class FindingConsonants { public static void main(String args[]) { String str = new String("Hi Welcome to Tutorialspoint"); for(int i=0; i