ICANWIN Posted September 11, 2013 Report Posted September 11, 2013 How to implement split functionality on string without any existing java library...evarikanna teluste koncham code rayandi... i wrote with string tokenizer, java substring with looping through array and substring but interviewer said i cannot use existing java libraries...i couldn't think of any logic at that point of time...evarikanna teluste answer let me know ..it was a very good question but nenu rayalekapoya code without using any java library...i appreciate any responses.
innovative Posted September 11, 2013 Report Posted September 11, 2013 em condition tho split cheyyali anta .. split func use cheyodhu ante, no regex/condition to split on !! split condition ivvaka pothe, only possiblity i could think of is - all the characters in the string must be unique and also he should give some index point where to split ..
ICANWIN Posted September 11, 2013 Author Report Posted September 11, 2013 [quote name='innovative' timestamp='1378868219' post='1304232846'] em condition tho split cheyyali anta .. split func use cheyodhu ante, no regex/condition to split on !! split condition ivvaka pothe, only possiblity i could think of is - all the characters in the string must be unique and also he should give some index point where to split .. [/quote] There is a string with say str1 = "abc,defghi, jklmn" ; Now split the string without using any existing java libraries ..u cant use inbuilt split function provided by java too. now result should be abc defghi jklmn
innovative Posted September 11, 2013 Report Posted September 11, 2013 we should use some looping technique .. assuming that string and char(at which we need to split) are given.. i didn't test this code.. jus wrote from my first thought, raw code .. algorithmic ... [CODE] String givenString= "abcdef"; String splitChar = "c"; StringBuilder finalString1 = null; StringBuilder finalString2 = null; int splitPoint = givenString.indexOf(splitChar); if(givenString.contains(splitChar)); { for(int j=0;j<splitPoint;j++) { finalString1.add(givenString.charAt(j)); } for(int k=splitPoint;k<givenString.length;k++) { finalString2.add(givenString.charAt(k)); } system.out.println(finalString1+" " +finalString2); } else { system.out.println("Dear interviewer, plz do check ur req..thrz no matching char to split "); } } [/CODE]
innovative Posted September 11, 2013 Report Posted September 11, 2013 [quote name='ICANWIN' timestamp='1378869860' post='1304232960'] There is a string with say str1 = "abc,defghi, jklmn" ; Now split the string without using any existing java libraries ..u cant use inbuilt split function provided by java too. now result should be abc defghi jklmn [/quote] then in the above alog, we can assign char as "," and find indexOf that char in the given String.. then append char by char to and from that index ... donno if this works .. check it ..
ICANWIN Posted September 11, 2013 Author Report Posted September 11, 2013 You cannot use charAt... nenu char at use chesa..charAt is inbuilt java function on string use cheyakudadu annadu
innovative Posted September 11, 2013 Report Posted September 11, 2013 [quote name='ICANWIN' timestamp='1378870066' post='1304232974'] You cannot use charAt... nenu char at use chesa [/quote] So we can not use any of the inbuilt java lib's ?? i thought other that String split function .. we can use them .. oops, forget it ...
dkchinnari Posted September 11, 2013 Report Posted September 11, 2013 [quote name='innovative' timestamp='1378870037' post='1304232968'] then in the above alog, we can assign char as "," and find indexOf that char in the given String.. then append char by char to and from that index ... donno if this works .. check it .. [/quote]
ICANWIN Posted September 11, 2013 Author Report Posted September 11, 2013 [quote name='innovative' timestamp='1378870165' post='1304232986'] So we can not use any of the inbuilt java lib's ?? i thought other that String split function .. we can use them .. oops, forget it ... [/quote] String tokenizer does this job and used in my prev project thousands of times. 3 ways lo answer rasi chupincha...em java inbuilt api methods use cheyakunda rayamannadu...really 20 mins lo enta alochinchina i couldn't answer..atleast i thought to know the answer now
dkchinnari Posted September 11, 2013 Report Posted September 11, 2013 [quote name='ICANWIN' timestamp='1378870370' post='1304233012'] String tokenizer does this job and used in my prev project thousands of times. 3 ways lo answer rasi chupincha...em java inbuilt api methods use cheyakunda rayamannadu...really 20 mins lo enta alochinchina i couldn't answer..atleast i thought to know the answer now [/quote]ft ki idi
ICANWIN Posted September 11, 2013 Author Report Posted September 11, 2013 [quote name='vishwamithra' timestamp='1378870425' post='1304233019'] ft ki idi [/quote] Full time kadu dude...contracting ke...google docs to interview...he can see that doc when i type anta...java mida confidence pogottadu...
dkchinnari Posted September 11, 2013 Report Posted September 11, 2013 [quote name='ICANWIN' timestamp='1378870496' post='1304233025'] Full time kadu dude...contracting ke...google docs to interview...he can see that doc when i type anta...java mida confidence pogottadu... [/quote] market inka set kaledha..java ila undhi ante
Thingarodu Posted September 11, 2013 Report Posted September 11, 2013 String str = "abcdef"; char delim = "c" char[] cArray = str.toCharArray(); for(int i=0; i<cArray.length; i++) { if(cArray[i] == c) break; } StringBuffer sb1 = new StringBuffer(); StringBuffer sb2 = new StringBuffer(); sb1.append(cArray, 0, c); sb2.append(cArray, c, c.length - c); Now sb1 and sb2 contains two strings which are split at char 'c' null checks need to be added
ICANWIN Posted September 11, 2013 Author Report Posted September 11, 2013 [quote name='vishwamithra' timestamp='1378870638' post='1304233037'] market inka set kaledha..java ila undhi ante [/quote] em chachindo i don't know ...its been 4 weeks that i am on bench. only 2 client calls vachayi and rondu ilane code test....ronditiki turpu tirigi dandam pettanu... i really lost confidence after these both client calls ...never my confidence was this low in last 3 and half yrs
ICANWIN Posted September 11, 2013 Author Report Posted September 11, 2013 [quote name='Thingarodu' timestamp='1378870780' post='1304233054'] String str = "abcdef"; char delim = "c" char[] cArray = str.toCharArray(); for(int i=0; i<cArray.length; i++) { if(cArray[i] == c) break; } StringBuffer sb1 = new StringBuffer(); StringBuffer sb2 = new StringBuffer(); sb1.append(cArray, 0, c); sb2.append(cArray, c, c.length - c); Now sb1 and sb2 contains two strings which are split at char 'c' null checks need to be added [/quote] u cannot use string buffer...
Recommended Posts