I have a method from which I need to return two values.I m confused as to how can I return two values.
public List<Class1> getCode(Long Code)
{
String Query1="Some Query";
List<Object[]> value = repos.getQuery(Query1);
List<Class1> counts = new ArrayList<>();
if (null != value)
{
Iterator<Object[]> rowItr = value.iterator();
while (rowItr.hasNext())
{
Class1 count = new Class1();
Object[] obj = rowItr.next();
if (null != obj)
{
if (null != obj[0])
{
count.setValuess1(obj[0].toString());
}
if (null != obj[1])
{
count.setValuess2(obj[1].toString());
}
}
counts.add(count);
return (List<Class1>) counts;
}
String Query2="SomeQuery" ;
List<Object[]> value2 = repos.getQuery(Query2);
List<Class2> count1s = new ArrayList<>();
if (null != value2)
{
Iterator<Object[]> rowItr1 = value2.iterator();
while (rowItr.hasNext())
{
Class2 countt = new Class2();
Object[] obj1 = rowItr1.next();
if (null != obj1)
{
if (null != obj1[0])
{
countt.setValuess1(obj1[0].toString());
}
if (null != obj1[1])
{
countt.setValuess2(Long.valueOf(obj1[1].toString()));
}
}
count1s.add(countt);
}
}
return (List<Class2>)count1s;
}
}
This is my Class1
public class1
{
private String valuess1;
private String valuess2;
private List<Class2>class2;
}
This is My Class2
public class Class2
{
private String valuess1;
private Long valuess2;
}
How can I return count1s and counts together .I have tried returning the value by the use of casting but it does not accept it.I have seen quiet a few solutions but none of them has worked for me.Any help would be appreciated.
getCodemethod instead of trying to return to values from a method.getCodemethod contains redundant code.