Hi Guys,
It's very simple
step1:convert your string to a character array
step2:Create an ArrayList add each string to this list and finally return list.
Program:
package logics;
import java.util.ArrayList;
import java.util.Iterator;
public class concatDemo {
public static void main(String []args)
{
String s1="shashi kumar";
String s2="shankar";
char name1[]=s1.toCharArray();
char name2[]=s2.toCharArray();
concatination(name1,name2);
}
public static void concatination(char[] name,char[] name1)
{
ArrayList<Character> list=new ArrayList<Character>();
for(char s:name)
{
list.add(s);
}
for(char s:name1)
{
list.add(s);
}
Iterator<Character > i=list.iterator();
while(i.hasNext())
{
System.out.print(i.next());
}
}
}
output:
--------------------------------
shashi kumarshankar
It's very simple
step1:convert your string to a character array
step2:Create an ArrayList add each string to this list and finally return list.
Program:
package logics;
import java.util.ArrayList;
import java.util.Iterator;
public class concatDemo {
public static void main(String []args)
{
String s1="shashi kumar";
String s2="shankar";
char name1[]=s1.toCharArray();
char name2[]=s2.toCharArray();
concatination(name1,name2);
}
public static void concatination(char[] name,char[] name1)
{
ArrayList<Character> list=new ArrayList<Character>();
for(char s:name)
{
list.add(s);
}
for(char s:name1)
{
list.add(s);
}
Iterator<Character > i=list.iterator();
while(i.hasNext())
{
System.out.print(i.next());
}
}
}
output:
--------------------------------
shashi kumarshankar
Không có nhận xét nào:
Đăng nhận xét