Posts

Showing posts with the label String

Duplicate occurrences of characters in String without Collections

I have searched multiple websites to find the answer how to identify the duplicate characters in a given string " AMBERROADSOFTWARE " without using Collections API. But, still no luck. So, finally me and my team member Ramanjulu has found the way to solve this problem. This is also one of the question which is asking multiple companies interviews. package com . javatbrains . practice ; public class FindDuplicatesFromString { public static void main ( String [] args ) { findUniqueChars (); findDuplicateChar (); findDuplicateWords (); } private static void findUniqueChars () { String str = "NALLAMACHU" ; int count = 0 ; String finalString = "" ; if ( str != null ) { for ( int i = 0 ; i < str . length (); i ++) { char initialChar = str . charAt ( i ); int length = str . length (); str = str . replaceAll ( str . charAt ( i ) + "" , "" ); count =

String rotation interview question for 5 Years of exprience

After long time I have got time to update my blog and help to the followers. These are the most commonly asking interview questions in string concept in java. String Rotation: How can you find one string is the rotation of another string? As we all know what the rotation means is, moving the first character of the string into last. When you keep doing the same, after certain moves you will get the initial string. This is what String Rotation is. Let say I have two strings as mentioned in the below, String str1 = “ABCDEF”; String str2 = “DEFABC”; Now, apply your logic to find str1 is the rotation of str2 or in reverse. First try your own, if not follow the below logic. This is also one of the CMMI Level5 company interview question. Steps to solve the above problem: If you want to find str1 is the rotation of str2. Let’s do concatenation of str2 with it. Means String str3 = str2+str2; Find the str3 contains the str1 or not by using the contains () method

How to generate excel sheet by using java

To generate an excel sheet by using java, we need to download the jxl.jar. This will help us to generate xls file by using predefined classes. For downloading jxl jar click here . This link will point to Maven repository from there you need to click on download button for downloading jar file. When jxl jar downloading will get complete, add the jar to project class path by following these steps. Right click on project --> goto properties --> select java build path --> select libraries --> click on add external jars button to browse downloaded jar path --> select jar and click on open button --> Ok. This jar file will provide few classes to design the excel sheet.  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 packag

String interview questions and answers

String interview questions and answers are placed the current post as of my experience in interviews. This will helps who are trying to attend interview as fresher as well as experience. If any one is facing any other questions which are not present in the current page, please drop me an email to " subbareddynallamachu@gmail.com ".  Q1:  String is a class or data type? A: String is a class in java.lang package. But, in java, all classes are also are considered as data types. So we can take String as data type also. Q2:  What is the difference between == and equals() methods in java? A: == operator compares the references of the String object. It does not compare the content of the object. equals() method compares the contents. While comparing the Strings, equals method should be used as it yields the correct result. Q3:  What is String constant pool? A: String constant pool is a separate block of memory where the String objects are held by JVM. If a String object is create