Jump to content

Java/j2Ee Interview Question


Recommended Posts

Posted

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.

  • Replies 48
  • Created
  • Last Reply

Top Posters In This Topic

  • ICANWIN

    23

  • Power Star

    6

  • innovative

    5

  • dinkuchaka

    4

Popular Days

Top Posters In This Topic

Posted

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 ..

Posted

[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

Posted

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 :D ");
}
}
[/CODE]

Posted

[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 .. :D check it ..

Posted

You cannot use charAt... nenu char at use chesa..charAt is inbuilt java function on string use cheyakudadu annadu

Posted

[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 ... :P

Posted

[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 .. :D check it ..
[/quote] #:~

Posted

[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 ... :P
[/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

Posted

[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 sCo_^Y

Posted

[quote name='vishwamithra' timestamp='1378870425' post='1304233019']
ft ki idi sCo_^Y
[/quote]


Full time kadu dude...contracting ke...google docs to interview...he can see that doc when i type anta...java mida confidence pogottadu... :3D_Smiles_216: :3D_Smiles_216: :3D_Smiles_216:

Posted

[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... :3D_Smiles_216: :3D_Smiles_216: :3D_Smiles_216:
[/quote] sFun_duh2 _*hiDe market inka set kaledha..java ila undhi ante

Posted

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

Posted

[quote name='vishwamithra' timestamp='1378870638' post='1304233037']
sFun_duh2 _*hiDe 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

Posted

[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...

×
×
  • Create New...